/* Reusable components */

/* Top header */
.top-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg-page);
  padding: 12px 16px 8px;
}
.page-title { font-size: 22px; font-weight: 800; margin: 0 0 8px; color: var(--text); }

/* Top tabs (Hot / New / Playlet) */
.top-tabs { display: flex; gap: 24px; padding: 8px 16px 4px; }
.top-tab {
  position: relative; padding: 8px 0;
  font-size: 16px; font-weight: 500; color: var(--text-secondary);
  background: none; border: 0; cursor: pointer;
}
.top-tab.active { color: var(--text); font-weight: 800; font-size: 18px; }
.top-tab.active::after {
  content: ''; position: absolute; left: 50%; bottom: 0;
  width: 24px; height: 3px; background: var(--primary); border-radius: 2px;
  transform: translateX(-50%);
}

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px;
  margin: 0 16px 12px;
  background: var(--bg-muted); border-radius: 20px;
  color: var(--text-tertiary); font-size: 14px;
}
.search-bar svg { flex: 0 0 18px; }

/* Footer tab bar */
.footer-tab {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 480px; height: 56px;
  display: flex; align-items: stretch;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 50;
}
.footer-tab .ft-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: none; border: 0; color: var(--text-tertiary); font-size: 11px;
}
.footer-tab .ft-item.active { color: var(--primary); }
.footer-tab .ft-item svg { width: 24px; height: 24px; }

/* Cards / Books */
.book-cover {
  position: relative; flex-shrink: 0;
  background: var(--bg-muted);
  border-radius: 8px; overflow: hidden;
  display: flex; align-items: flex-end;
  color: #fff; font-weight: 700;
}
.book-cover .bc-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: center;
  background: var(--bg-muted);
}
.book-cover .bc-title {
  position: relative;            /* keeps it above the absolute img */
  z-index: 1;
  width: 100%; padding: 8px 10px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.65));
  font-size: 13px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.book-cover.vip::before {
  content: 'VIP'; position: absolute; top: 6px; left: 6px; z-index: 2;
  background: var(--vip-gold-bg); color: #6B4D00;
  font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px;
}

/* Banner row */
.banner-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; padding: 0 16px 12px;
}
.banner-tile {
  position: relative;
  aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden;
  background: var(--bg-muted);
  cursor: pointer;
}
.banner-tile .banner-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: center;
}

/* Section header */
.section { padding: 16px 0 8px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 8px;
}
.section-title h3 { margin: 0; font-size: 17px; font-weight: 800; }
.section-title .more { font-size: 13px; color: var(--text-tertiary); background: none; border: 0; }

/* Edit Recommend (horizontal scroll) */
.edit-rec { display: flex; gap: 12px; padding: 0 16px 4px; overflow-x: auto; scroll-snap-type: x mandatory; }
.edit-rec .er-item { flex: 0 0 88px; scroll-snap-align: start; cursor: pointer; }
.edit-rec .er-item .book-cover { width: 88px; height: 118px; }
.edit-rec .er-item .er-title {
  margin-top: 6px; font-size: 12px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.3;
}

/* Recommend cards (large) */
.rec-list { padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
.rec-card {
  display: flex; gap: 12px; padding: 12px;
  background: var(--bg-card); border-radius: 12px; cursor: pointer;
}
.rec-card .book-cover { width: 96px; height: 128px; }
.rec-card .rc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.rec-card .rc-title { font-size: 16px; font-weight: 800; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.rec-card .rc-content {
  font-size: 13px; line-height: 1.45; color: var(--text-secondary);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.rec-card .rc-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rec-card .rc-author { font-size: 12px; color: var(--text-tertiary); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--bg-muted); color: var(--text-secondary); }

/* For You grid */
.fy-grid { padding: 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fy-card { cursor: pointer; }
.fy-card .book-cover { width: 100%; aspect-ratio: 3 / 4; }
.fy-card .fy-title {
  margin-top: 6px; font-size: 14px; font-weight: 700; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.fy-card .fy-meta { font-size: 11px; color: var(--text-tertiary); display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.fy-card .fy-likes { display: inline-flex; align-items: center; gap: 2px; }
.loading-more { text-align: center; padding: 16px; color: var(--text-tertiary); font-size: 13px; }

.site-copyright {
  padding: 10px 16px 18px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.4;
}

/* My tab */
.my-userCard { display: flex; align-items: center; gap: 12px; padding: 16px; background: var(--bg-card); }
.avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #fb7185, #a78bfa);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 22px;
}
.my-userCard .uc-name { font-size: 16px; font-weight: 800; }
.my-userCard .uc-id { font-size: 12px; color: var(--text-tertiary); }
.my-userCard .uc-sign { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.wallet-card {
  display: flex; gap: 12px; margin: 12px 16px; padding: 16px;
  background: var(--bg-card); border-radius: 12px;
}
.wallet-col { flex: 1; cursor: pointer; }
.wallet-col .wc-num { font-size: 22px; font-weight: 800; }
.wallet-col .wc-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.svip-card {
  margin: 12px 16px; padding: 16px;
  background: var(--vip-gold-bg); border-radius: 12px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  color: #6B4D00;
}
.svip-card .svip-text { flex: 1; }
.svip-card .svip-text .st-title { font-size: 15px; font-weight: 800; }
.svip-card .svip-text .st-sub { font-size: 12px; opacity: .85; margin-top: 2px; }
.svip-card .svip-cta {
  background: #6B4D00; color: #FFF1C2; padding: 8px 14px; border-radius: 16px;
  font-size: 13px; font-weight: 700;
}

.list-rows { background: var(--bg-card); margin: 12px 16px; border-radius: 12px; overflow: hidden; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; cursor: pointer;
}
.list-row:last-child { border-bottom: 0; }
.list-row .lr-icon {
  width: 24px; height: 24px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; background: var(--bg-muted); color: var(--primary);
}
.list-row .lr-label { flex: 1; font-size: 14px; }
.list-row .lr-right { color: var(--text-tertiary); font-size: 13px; }
.list-row svg.chev { width: 16px; height: 16px; color: var(--text-tertiary); }

/* Toggle */
.switch { position: relative; width: 44px; height: 26px; }
.switch input { display: none; }
.switch .slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 13px;
  transition: background .15s;
}
.switch .slider::before {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 22px; height: 22px; background: #fff; border-radius: 50%;
  transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.5);
  display: flex; align-items: stretch; justify-content: center;
}
.modal {
  position: relative;
  width: 100%; max-width: 480px;
  /* Lock the sheet to exactly the visible viewport. Header lives on the
     non-scrolling top; the rest of the modal is a flex child that fills
     remaining space and scrolls internally. dvh handles mobile browser
     chrome correctly, with vh as a fallback. */
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  background: var(--bg-page);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  /* Pinned to the top of the modal because it's a flex item that doesn't
     grow or shrink. The actually-scrolling area sits below it. */
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
}
/* Every non-header direct child of .modal becomes the scroll surface.
   `min-height: 0` releases flex's default `auto` that would otherwise
   prevent the child from shrinking below its content size and blocking
   overflow. */
.modal > *:not(.modal-header) {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-header .search-input {
  flex: 1; height: 40px; padding: 0 14px; border-radius: 20px;
  background: var(--bg-muted); border: 0; outline: none; font-size: 14px;
  color: var(--text);
}
.modal-header .cancel-btn { background: none; border: 0; color: var(--primary); font-size: 15px; }

.rank-list { padding: 8px 0 80px; }
.rank-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
}
.rank-rank {
  width: 28px; height: 28px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: var(--text-tertiary);
}
.rank-rank.gold   { color: #fff; background: linear-gradient(135deg,#FFD56B,#E0A300); border-radius: 6px; }
.rank-rank.silver { color: #fff; background: linear-gradient(135deg,#E5E5E5,#9AA0A6); border-radius: 6px; }
.rank-rank.bronze { color: #fff; background: linear-gradient(135deg,#E2A26B,#995A2E); border-radius: 6px; }
.rank-row .book-cover { width: 44px; height: 60px; }
.rank-row .rr-title { font-weight: 700; font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.rank-row .rr-meta { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; }

/* Empty state */
.empty-state {
  padding: 60px 32px; text-align: center;
  color: var(--text-tertiary); font-size: 14px;
}
.empty-state .link { color: var(--primary); cursor: pointer; }

/* Toast */
#toast-root .toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 16px; border-radius: 6px;
  font-size: 13px; z-index: 200; animation: fade .2s;
}

/* Promotional banner (article details top) */
.promo-banner {
  margin: 8px 16px 12px; padding: 10px 14px;
  background: var(--vip-gold-bg); color: #6B4D00;
  border-radius: 10px; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}

/* Detail title */
.article-title { padding: 12px 16px 4px; font-size: 22px; font-weight: 800; line-height: 1.25; color: var(--reader-title); }
.article-meta { padding: 0 16px 16px; color: var(--text-tertiary); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Login */
.login-page { padding: 32px 24px; }
.login-page h1 { margin: 0 0 24px; font-size: 24px; }
.gsi-button {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 16px; background: #fff; color: #3c4043;
  border: 1px solid #dadce0; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer; box-shadow: 0 1px 2px rgba(60,64,67,.1);
}

/* Settings */
.settings-page { padding: 8px 0; }
.settings-article {
  margin: 14px 16px 32px;
  padding: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.settings-article-meta {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1.2;
}
.settings-article-lead {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}
.settings-article-section {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.settings-article-section h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
}
.settings-article-section p {
  margin: 0 0 10px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.65;
}
.settings-article-section p:last-child { margin-bottom: 0; }

/* My subpages */
.subpage-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 12px;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
}
.subpage-back {
  width: 36px; height: 36px; border: 0; border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-muted); color: var(--text);
}
.subpage-back svg { transform: rotate(180deg); }
.subpage-title {
  flex: 1; text-align: center;
  font-size: 16px; font-weight: 800;
}
.subpage-head-spacer { width: 36px; height: 36px; }
.subpage-summary {
  margin: 16px; padding: 18px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.summary-label { font-size: 12px; color: var(--text-tertiary); }
.summary-value { margin-top: 4px; font-size: 28px; font-weight: 800; color: var(--text); }
.summary-note { margin-top: 4px; font-size: 12px; color: var(--text-secondary); }
.subpage-list {
  margin: 12px 16px 28px;
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.subpage-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.subpage-row:last-child { border-bottom: 0; }
.subpage-row-main { flex: 1; min-width: 0; }
.subpage-row-title { font-size: 14px; font-weight: 700; color: var(--text); }
.subpage-row-sub { margin-top: 2px; font-size: 12px; color: var(--text-tertiary); line-height: 1.35; }
.subpage-row-value {
  max-width: 112px; text-align: right;
  font-size: 13px; font-weight: 700; color: var(--primary);
}
.subpage-form {
  margin: 12px 16px 28px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.subpage-field {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 14px;
  font-size: 12px; color: var(--text-tertiary);
}
.subpage-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-page);
  color: var(--text);
  font: inherit;
  outline: none;
}
.subpage-textarea {
  height: 150px;
  resize: vertical;
}
.subpage-help {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
