/* 书窝 —— 阅读器样式
   排版参数参考微信读书线上 CSS 抽取结果：
   字体栈 PingFang SC / Microsoft YaHei；正文字号 16px 起；
   行高比约 1.6；主题色 #212832 文字 / #1b88ee 强调 / #f4f5f7 背景；圆角 12/16/20。 */

:root {
  --accent: #1b88ee;
  --radius: 16px;
  --radius-sm: 12px;
  --fs: 18px;
  --lh: 1.75;
  --margin: 28px;
  --font-family: -apple-system, "SF UI Text", "PingFang SC", "Lucida Grande",
    "Microsoft YaHei", system-ui, sans-serif;
  --serif-family: "Songti SC", "SimSun", "Noto Serif CJK SC", Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--font-family);
  background: var(--bg); color: var(--fg);
  overscroll-behavior: none;
}

/* 主题 */
body.theme-light { --bg:#f4f5f7; --card:#fff; --fg:#212832; --fg-2:#5d646e; --fg-3:#99a0aa; --line:#e6e8eb; --reader-bg:#fff; }
body.theme-sepia { --bg:#f3ead8; --card:#fbf3e3; --fg:#3a3128; --fg-2:#6b5d4a; --fg-3:#a2957f; --line:#e2d6bf; --reader-bg:#f7efdd; }
body.theme-dark  { --bg:#14161a; --card:#1c1f24; --fg:#e6e8ea; --fg-2:#a8b0ba; --fg-3:#6f7883; --line:#2a2f36; --reader-bg:#14161a; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button.ghost { padding: 6px 12px; border-radius: var(--radius-sm); background: var(--card); border: 1px solid var(--line); }
button.icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; }

.view { height: 100%; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* 密码门 */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--bg);
}
.gate-card {
  width: min(360px, 86vw); padding: 32px 24px;
  background: var(--card); border-radius: 20px; border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.06);
}
.gate-logo { font-size: 26px; font-weight: 700; letter-spacing: 2px; }
.gate-sub { margin: 0; color: var(--fg-3); font-size: 13px; }
.gate-card input {
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  font-size: 15px; text-align: center;
}
.gate-card button {
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
}
.gate-err { margin: 0; color: #fa3a3a; font-size: 13px; min-height: 18px; }

/* 书架 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 10px; gap: 12px;
}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.grid {
  display: grid; gap: 18px 16px; padding: 8px 20px 40px;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}
.book { display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
.book-cover {
  aspect-ratio: 3/4; border-radius: var(--radius-sm); overflow: hidden;
  background: linear-gradient(160deg, #dfe6ee, #c9d3de);
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(20,30,50,.10);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .ph { padding: 10px; font-size: 13px; line-height: 1.35; text-align: center; color: #3c4653; }
.book-title { font-size: 13px; line-height: 1.35; }
.book-meta { font-size: 11px; color: var(--fg-3); }
.book-del {
  font-size: 11px; color: var(--fg-3); text-align: right;
  opacity: 0; transition: opacity .15s;
}
.book:hover .book-del { opacity: 1; }

.empty { margin: 60px auto; text-align: center; color: var(--fg-3); font-size: 14px; }
.empty-title { font-size: 17px; color: var(--fg-2); margin-bottom: 6px; }

/* 阅读器 */
.reader { position: relative; background: var(--reader-bg); height: 100%; overflow: hidden; }
.paged, .flow-wrap { position: absolute; inset: 0; }

/* 桌面端限制行长，一行别超过 ~45 字 */
.paged {
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding: 52px 0 64px;
  max-width: 860px;
  margin-inline: auto;
}
.paged::-webkit-scrollbar { display: none; }

.flow {
  width: calc(var(--page-w, 100vw) - var(--margin) * 2);
  margin: 0 auto;
  height: 100%;
  column-width: calc(var(--page-w, 100vw) - var(--margin) * 2);
  column-gap: calc(var(--margin) * 2);
  column-fill: auto;
  font-size: var(--fs);
  line-height: var(--lh);
  text-align: justify;
  word-break: break-word;
}
body.font-serif .flow { font-family: var(--serif-family); }

.paged .flow { height: 100%; }
.scroll-mode .paged { overflow-y: auto; overflow-x: hidden; scroll-snap-type: none; padding: 52px 0 0; }
.scroll-mode .flow {
  width: auto; margin: 0; column-width: auto; column-count: 1; height: auto;
  padding-left: var(--margin); padding-right: var(--margin);
  padding-bottom: 120px;
}

.flow p { margin: 0 0 .85em; text-indent: 2em; }
.flow h1, .flow h2, .flow h3 { font-size: 1.15em; margin: 1.2em 0 .6em; text-indent: 0; }
.flow img { max-width: 100%; height: auto; display: block; margin: 1em auto; break-inside: avoid; }
.flow blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--fg-2); }
.flow mark.hl { background: rgba(27,136,238,.18); border-bottom: 1px solid rgba(27,136,238,.5); }

.chrome {
  position: absolute; left: 0; right: 0; z-index: 20;
  background: color-mix(in srgb, var(--reader-bg) 92%, transparent);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  transition: transform .22s ease, opacity .22s ease;
}
.chrome.top { top: 0; border-bottom: 1px solid var(--line); padding-top: calc(10px + env(safe-area-inset-top)); }
.chrome.bottom { bottom: 0; border-top: 1px solid var(--line); }
.chrome.hide { opacity: 0; pointer-events: none; }
.chrome.top.hide { transform: translateY(-100%); }
.chrome.bottom.hide { transform: translateY(100%); }

.chrome-title { flex: 1; font-size: 14px; color: var(--fg-2); text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress-wrap { flex: 1; display: flex; align-items: center; gap: 10px; }
.progress-bar { flex: 1; height: 3px; border-radius: 9999px; background: var(--line); overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; }
.progress-text { font-size: 12px; color: var(--fg-3); min-width: 34px; }

.tap { position: absolute; top: 0; bottom: 0; width: 28%; z-index: 10; }
.tap.prev { left: 0; }
.tap.next { right: 0; }

/* 抽屉 */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-height: 72vh; transform: translateY(102%);
  transition: transform .26s cubic-bezier(.2,.8,.2,1);
  background: var(--card); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0,0,0,.12);
}
.sheet.open { transform: translateY(0); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.sheet-body { overflow: auto; padding: 8px 6px 24px; }
.toc-item { padding: 12px 16px; font-size: 14px; border-radius: 10px; color: var(--fg-2); }
.toc-item.active { color: var(--accent); background: rgba(27,136,238,.08); }
.toc-item .lv2 { padding-left: 16px; font-size: 13px; }
.mark-item { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.mark-item q { color: var(--fg); }
.mark-item .note { color: var(--fg-2); font-size: 13px; margin-top: 6px; }
.mark-item time { display: block; color: var(--fg-3); font-size: 11px; margin-top: 6px; }

.settings { padding: 18px; display: flex; flex-direction: column; gap: 18px; }
.settings label { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 14px; }
.settings input[type=range] { flex: 1; accent-color: var(--accent); }
.settings select {
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font-size: 14px;
}

.sel-menu {
  position: absolute; z-index: 40; display: flex; gap: 2px;
  background: #212832; color: #fff; border-radius: 9999px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.sel-menu button { padding: 6px 14px; border-radius: 9999px; font-size: 13px; }
.sel-menu button:active { background: rgba(255,255,255,.14); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px);
  background: #212832; color: #fff; padding: 10px 16px; border-radius: 9999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
