/* 拾卷 · 小说阅读器 */

:root {
  --fs: 19px;            /* 正文字号 */
  --lh: 1.9;             /* 正文行距 */
  --pw: 760px;           /* 版心宽度 */
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
  --sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-family: var(--serif);
  --radius: 10px;
  --header-h: 56px;
  --footer-h: 44px;
}

body[data-theme="paper"] { --bg:#f6f1e7; --fg:#3b3226; --muted:#8a7d68; --panel:#fffdf7; --border:#e6dcc8; --accent:#9a6b3f; --card:#fffdf7; --shadow:0 2px 12px rgba(120,90,40,.08); }
body[data-theme="light"] { --bg:#f7f8fa; --fg:#2c3038; --muted:#8b93a1; --panel:#ffffff; --border:#e4e7ec; --accent:#4a7dbd; --card:#ffffff; --shadow:0 2px 12px rgba(30,40,60,.08); }
body[data-theme="green"] { --bg:#dfe9dc; --fg:#2f3a2f; --muted:#6f7f6f; --panel:#eef4ea; --border:#c9d8c4; --accent:#4c7a4c; --card:#eef4ea; --shadow:0 2px 12px rgba(40,70,40,.10); }
body[data-theme="dark"]  { --bg:#16181d; --fg:#c9ccd3; --muted:#6d7480; --panel:#1e2128; --border:#2c303a; --accent:#7fa8e0; --card:#1e2128; --shadow:0 2px 14px rgba(0,0,0,.4); }
body.sans { --font-family: var(--sans); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-family); transition: background .25s, color .25s; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------------- 书架 ---------------- */
.shelf-header { padding: 52px 24px 10px; text-align: center; }
.shelf-header h1 { margin: 0; font-size: 36px; font-weight: 600; letter-spacing: .35em; text-indent: .35em; }
.subtitle { margin: 8px 0 0; color: var(--muted); font-size: 14px; letter-spacing: .18em; }
.shelf-actions { margin-top: 24px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.btn { border: 1px solid var(--border); background: var(--panel); color: var(--fg); padding: 9px 20px; border-radius: 999px; font-size: 14px; cursor: pointer; transition: .15s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.wide { width: 100%; border-radius: 8px; }

.shelf-grid { max-width: 1080px; margin: 30px auto 60px; padding: 0 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 22px; }
.book-card { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.book-card:hover { transform: translateY(-3px); }
.cover { height: 150px; display: flex; align-items: center; justify-content: center; font-size: 44px; font-weight: 600; color: rgba(255,255,255,.92); text-shadow: 0 2px 8px rgba(0,0,0,.25); }
.book-info { padding: 12px 14px 14px; }
.book-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.book-del { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border: none; border-radius: 50%; background: rgba(0,0,0,.35); color: #fff; cursor: pointer; font-size: 13px; line-height: 1; opacity: 0; transition: .15s; }
.book-del:hover { background: rgba(0,0,0,.55); }
.book-card:hover .book-del { opacity: 1; }

.shelf-empty { text-align: center; color: var(--muted); padding: 70px 20px; }
.shelf-empty .big { font-size: 54px; margin-bottom: 16px; }
.shelf-empty p { margin: 6px 0; }
.shelf-empty .sub { font-size: 13px; }
.shelf-empty .btn { margin-top: 18px; }

.shelf-tabs { margin-top: 22px; display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 999px; background: var(--panel); }
.shelf-tab { border: none; background: none; color: var(--muted); padding: 8px 22px; border-radius: 999px; font-size: 14px; cursor: pointer; display: flex; align-items: center; gap: 7px; transition: .15s; }
.shelf-tab:hover { color: var(--fg); }
.shelf-tab.active { background: var(--accent); color: #fff; }
.shelf-tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); transition: .15s; }
.shelf-tab .dot.ok { background: #58b368; }
.shelf-tab .dot.err { background: #d0604f; }
.shelf-tab.active .dot.ok { background: #c9f2d1; }
.shelf-tab.active .dot.err { background: #f2b8ae; }

.cloud-badge { position: absolute; top: 8px; left: 8px; z-index: 1; background: rgba(0,0,0,.38); color: #fff; font-size: 11px; padding: 3px 9px; border-radius: 999px; letter-spacing: .1em; }

.text-input { display: block; width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 9px; font-family: inherit; }
.text-input:focus { outline: none; border-color: var(--accent); }
.text-input::placeholder { color: var(--muted); }

.backup-btns { display: flex; gap: 8px; }
.backup-btns .btn { flex: 1; padding: 8px 0; font-size: 13px; }

/* 云端账号（管理后台在独立页面 admin.html，样式见 css/admin.css） */
.cloud-user { margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 13px; }
.cloud-user .header-btn { padding: 4px 12px; font-size: 12px; }
.cloud-form { width: min(320px, 86vw); margin: 0 auto; text-align: left; }

/* EPUB 插图 */
.epub-img { text-indent: 0; text-align: center; margin: 1.2em 0; }
.epub-img img { max-width: 100%; max-height: 56vh; display: block; margin: 0 auto; border-radius: 4px; }

/* ---------------- 全文搜索 ---------------- */
.search-bar { position: relative; width: min(480px, 86vw); margin: 18px auto 0; }
#search-input { width: 100%; border: 1px solid var(--border); background: var(--panel); color: var(--fg); border-radius: 999px; padding: 10px 40px 10px 18px; font-size: 14px; font-family: inherit; }
#search-input:focus { outline: none; border-color: var(--accent); }
#search-input::placeholder { color: var(--muted); }
.search-clear { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border: none; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.search-clear:hover { color: var(--fg); background: var(--bg); }

.search-results { max-width: 860px; margin: 26px auto 60px; padding: 0 24px; }
.sr-book { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.sr-head { display: flex; align-items: baseline; gap: 10px; padding: 12px 16px; cursor: pointer; flex-wrap: wrap; }
.sr-head:hover { background: var(--bg); }
.sr-title { font-weight: 600; font-size: 15px; }
.sr-count { font-size: 12px; color: var(--muted); }
.sr-body { border-top: 1px solid var(--border); }
.sr-hit { display: block; width: 100%; text-align: left; border: none; border-bottom: 1px solid var(--border); background: none; color: var(--fg); padding: 10px 16px; font-size: 13px; line-height: 1.8; cursor: pointer; }
.sr-hit:last-child { border-bottom: none; }
.sr-hit:hover { background: var(--bg); }
.sr-ch { color: var(--accent); font-weight: 600; margin-right: 8px; }
.sr-snippet { color: var(--muted); }
.sr-hit mark { background: transparent; color: var(--accent); font-weight: 700; }
.sr-none { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------------- 翻页模式（body.paged） ---------------- */
/* 列距 = 100vw - 列宽，使单页位移恰好等于视口宽：相邻页完全移出屏幕，不漏字 */
body.paged { --colw: min(var(--pw), calc(100vw - 40px)); --page-gap: calc(100vw - var(--colw)); }
body.paged #reader-main { display: flex; flex-direction: column; overflow: hidden; height: 100vh; box-sizing: border-box; padding: calc(var(--header-h) + 8px) 0 calc(var(--footer-h) + 8px); }
body.paged #chapter-container { max-width: none; width: 100%; flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 0; }
body.paged #chapter-title { flex: none; max-width: var(--pw); margin: 6px auto 14px; padding: 0 24px; box-sizing: content-box; max-height: 1.5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 正文做固定高度多列：一列即一页，溢出列向右排布，用 transform 翻页 */
body.paged #chapter-content { flex: 1; min-height: 0; width: var(--colw); margin: 0 auto; column-width: var(--colw); column-gap: var(--page-gap); column-fill: auto; overflow: visible; will-change: transform; }
body.paged .chapter-nav { display: none; }

.page-zones { display: none; }
body.paged .page-zones { display: flex; position: fixed; top: var(--header-h); bottom: var(--footer-h); left: 0; right: 0; z-index: 15; pointer-events: none; }
.page-zone { pointer-events: auto; width: 14%; border: none; background: none; color: var(--muted); font-size: 30px; opacity: 0; cursor: pointer; transition: opacity .15s; }
.page-zone.left { margin-right: auto; }
.page-zone.right { margin-left: auto; }
.page-zone:hover { opacity: .6; }

.drop-hint { position: fixed; inset: 0; background: rgba(0,0,0,.45); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 22px; letter-spacing: .1em; z-index: 90; pointer-events: none; }

/* ---------------- 阅读器 ---------------- */
.reader-header { position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); display: flex; align-items: center; gap: 8px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 20; }
.icon-btn { border: none; background: none; color: var(--fg); width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 17px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--bg); }
.reader-title { flex: 1; font-size: 15px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-btn { border: 1px solid var(--border); background: none; color: var(--fg); padding: 6px 14px; border-radius: 999px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.header-btn:hover { border-color: var(--accent); color: var(--accent); }

#reader-main { padding: calc(var(--header-h) + 28px) 20px calc(var(--footer-h) + 40px); }
#chapter-container { max-width: var(--pw); margin: 0 auto; }
#chapter-title { font-size: calc(var(--fs) + 7px); font-weight: 600; text-align: center; margin: 16px 0 32px; }
#chapter-content p { font-size: var(--fs); line-height: var(--lh); text-indent: 2em; margin: 0 0 .85em; text-align: justify; }
.chapter-nav { display: flex; gap: 12px; margin-top: 46px; }
.chapter-nav button { flex: 1; border: 1px solid var(--border); background: var(--panel); color: var(--fg); padding: 11px 0; border-radius: 8px; font-size: 14px; cursor: pointer; transition: .15s; }
.chapter-nav button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.chapter-nav button:disabled { opacity: .4; cursor: default; }

.reader-footer { position: fixed; bottom: 0; left: 0; right: 0; height: var(--footer-h); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); z-index: 20; }
#progress-bar { position: fixed; bottom: var(--footer-h); left: 0; height: 2px; width: 0; background: var(--accent); z-index: 21; transition: width .12s linear; }

/* ---------------- 抽屉 ---------------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
.drawer { position: fixed; top: 0; bottom: 0; width: min(84vw, 340px); background: var(--panel); z-index: 40; display: flex; flex-direction: column; box-shadow: 0 0 30px rgba(0,0,0,.2); transition: transform .25s ease; }
.drawer.left { left: 0; transform: translateX(-105%); }
.drawer.right { right: 0; transform: translateX(105%); }
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }

.toc-list { overflow-y: auto; flex: 1; padding: 8px 0; }
.toc-item { display: block; width: 100%; text-align: left; padding: 10px 18px; border: none; background: none; color: var(--fg); font-size: 14px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc-item:hover { background: var(--bg); }
.toc-item.active { color: var(--accent); font-weight: 600; background: var(--bg); }

.settings-body { flex: 1; overflow-y: auto; padding: 20px 18px; }
.setting { margin-bottom: 24px; }
.setting > label { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 9px; }
.setting .val { color: var(--fg); font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: 160px; }
.stepper button { flex: 1; border: none; background: none; font-size: 17px; padding: 7px 0; cursor: pointer; color: var(--fg); }
.stepper button:hover { background: var(--bg); }
.stepper .val { flex: 1.6; text-align: center; font-size: 14px; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: none; background: none; padding: 9px 0; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button.active { background: var(--accent); color: #fff; }

.swatches { display: flex; gap: 12px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* ---------------- 其他 ---------------- */
.toast { position: fixed; left: 50%; bottom: 64px; transform: translateX(-50%); background: rgba(30,30,34,.92); color: #fff; padding: 10px 20px; border-radius: 999px; font-size: 13px; z-index: 100; max-width: 86vw; text-align: center; }

@media (max-width: 640px) {
  .shelf-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .cover { height: 120px; font-size: 36px; }
  #reader-main { padding-left: 14px; padding-right: 14px; }
  .footer-hint { display: none; }
}
