/* =================================================================
   Biquge bookshelf — mobile-first, minimalist, themeable
   ================================================================= */

/* Theme variables are overridden by .theme-* classes below. */
:root {
  --bg: #f4ecd8;
  --bg-2: #ede2c4;
  --fg: #2a2520;
  --fg-soft: #6b655c;
  --fg-muted: #9c958a;
  --primary: #7a5a3a;
  --primary-on: #fff;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --line: rgba(0,0,0,.08);
  --radius: 10px;
  --content-pad: 5vw;
  --max-width: 720px;
  --font-size: 18px;
  --font-stack: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC',
                'Hiragino Sans GB', 'Microsoft YaHei', 'Source Han Sans CN', sans-serif;
}

.theme-paper {
  --bg: #f4ecd8; --bg-2: #ede2c4; --fg: #2a2520; --fg-soft: #6b655c;
  --fg-muted: #9c958a; --primary: #7a5a3a; --line: rgba(0,0,0,.08);
}
.theme-light {
  --bg: #fff; --bg-2: #f5f6f8; --fg: #1a1a1a; --fg-soft: #444;
  --fg-muted: #888; --primary: #2563eb; --line: rgba(0,0,0,.07);
}
.theme-eye {
  --bg: #c8d3c0; --bg-2: #b9c8af; --fg: #1b2422; --fg-soft: #4a544f;
  --fg-muted: #6a766f; --primary: #4a6a4c; --line: rgba(0,0,0,.08);
}
.theme-dark {
  --bg: #161618; --bg-2: #1f1f23; --fg: #d6d6d6; --fg-soft: #9f9f9f;
  --fg-muted: #6f6f6f; --primary: #f0a060; --line: rgba(255,255,255,.07);
}

.font-serif { --font-stack: 'Source Han Serif CN', 'Songti SC', 'SimSun', 'STSong', serif; }
.font-sans  { --font-stack: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-stack);
  font-size: var(--font-size);
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .3s ease, color .3s ease;
}

a { color: var(--primary); text-decoration: none; }
a:active { opacity: .7; }
button { font-family: inherit; cursor: pointer; }

/* ---------- App bar ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center;
  padding: 14px 5vw;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.app-bar h1 {
  flex: 1; margin: 0;
  font-size: 17px; font-weight: 600;
  color: var(--fg);
}
.app-bar .ip-tag,
.app-bar .back-btn {
  font-size: 13px; color: var(--fg-muted);
}

/* ---------- Container ---------- */
.container {
  padding: 24px 5vw 80px;
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ---------- Shelf ---------- */
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.book-card {
  display: block;
  background: var(--bg-2);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .15s ease;
}
.book-card:active { transform: scale(.97); }
.book-card .cover {
  aspect-ratio: 3 / 4;
  background-size: cover;
  background-position: center;
  background-color: #d4c5a9;
}
.book-card .cover-empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
}
.book-card .meta {
  padding: 10px 12px;
}
.book-card .title {
  font-weight: 600; font-size: 14px;
  color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book-card .author {
  font-size: 12px; color: var(--fg-soft);
  margin-top: 2px;
}
.book-card .badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  background: var(--primary);
  color: var(--primary-on);
  font-size: 11px;
  border-radius: 100px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 24px 0 12px;
}
.recent-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 8px;
}
.recent-card {
  flex: 0 0 60%;
  scroll-snap-align: start;
  padding: 16px;
  background: var(--bg-2);
  border-radius: var(--radius);
  color: var(--fg);
}
.recent-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 8px;
}
.recent-meta { font-size: 13px; color: var(--fg-soft); }

.empty {
  text-align: center;
  padding: 48px 0;
  color: var(--fg-muted);
}
.empty pre {
  display: inline-block;
  padding: 8px 16px;
  background: var(--bg-2);
  border-radius: 6px;
}

/* ---------- TOC ---------- */
.intro {
  padding: 14px 16px;
  background: var(--bg-2);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--fg-soft);
  margin-bottom: 20px;
  line-height: 1.6;
}
.toc-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 16px;
  font-size: 14px;
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--line);
  flex: 1;
}
.btn.primary { background: var(--primary); color: var(--primary-on); border: none; }

.chapter-list {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--line);
}
.chapter-item {
  display: flex; align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  color: var(--fg);
}
.chapter-item.read { color: var(--fg-muted); }
.chapter-no {
  display: inline-block;
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  margin-right: 14px;
  min-width: 44px;
}
.chapter-title { flex: 1; }
.chapter-wc {
  font-size: 12px;
  color: var(--fg-muted);
  margin-left: 8px;
}

/* ---------- Reader ---------- */
.reader-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center;
  gap: 8px;
  padding: 12px 4vw;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.reader-bar .bar-title {
  flex: 1;
  display: flex; flex-direction: column;
  min-width: 0;
}
.reader-bar .book-title {
  font-size: 12px;
  color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reader-bar .chapter-title {
  font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--fg);
}
.nav-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 6px;
}

.reader-main {
  padding: 24px var(--content-pad) 0;
  max-width: var(--max-width);
  margin: 0 auto;
}
.reader-content {
  margin-bottom: 80px;
}
.chapter-h1 {
  font-size: 22px; font-weight: 700;
  margin: 24px 0;
  text-align: center;
}
.chapter-body p {
  margin: 0 0 1.4em;
  text-indent: 2em;
}
.chapter-body p:last-child { margin-bottom: 0; }

.reader-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0 80px;
  border-top: 1px solid var(--line);
  margin-top: 40px;
  font-size: 14px;
}
.reader-nav .progress {
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* mode-slide: 整章节一页到底；切换通过按钮 / 滑动 */
.mode-slide .reader-content { padding-bottom: 12vh; }
.mode-scroll .reader-content { padding-bottom: 40vh; }

/* ---------- Settings panel ---------- */
.settings-panel { position: fixed; inset: 0; z-index: 100; }
.settings-panel[hidden] { display: none; }
.settings-mask {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.4);
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.settings-card {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 16px 6vw 32px;
  animation: slide-up .25s ease-out;
}
@keyframes slide-up { from { transform: translateY(100%) } to { transform: none } }

.settings-card h3 {
  font-size: 16px; font-weight: 600;
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.setting-row {
  display: flex; align-items: center;
  margin: 14px 0;
}
.setting-row label {
  flex: 0 0 56px;
  font-size: 13px;
  color: var(--fg-soft);
}
.seg {
  flex: 1;
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.seg button {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 6px;
  font-size: 13px;
  color: var(--fg-soft);
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: none; }
.seg button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-on);
}
.seg.themes button { padding: 8px 6px; }
.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.1);
  margin-right: 6px;
  vertical-align: -2px;
}
.swatch-paper { background: #f4ecd8; }
.swatch-light { background: #fff; }
.swatch-eye   { background: #c8d3c0; }
.swatch-dark  { background: #161618; }
