/* style.css —— 站点外壳样式
 *
 * 排版相关的规则（纸张尺寸、正文字号/行高/段间距）**不在这里**，
 * 由 js/layout-css.js 按 /api/layout 动态注入。
 * 这个文件只负责「纸张之外」的界面部分。
 */

:root {
  --bg: #f4f3f0;
  --card: #ffffff;
  --ink: #24241f;
  --ink-2: #6c6b64;
  --ink-3: #9a998f;
  --line: rgba(0, 0, 0, 0.1);
  --accent: #1f6f5c;
  --accent-soft: #e6f0ec;
  --danger: #a3372c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 18px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC",
    "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ------------------------------------------------------------------ 顶栏 */
.site-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 243, 240, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-head .wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  padding-bottom: 0;
}
.brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand span { color: var(--accent); }
.head-spacer { flex: 1; }

/* 顶栏「电脑版 / 手机版」切换。当前端高亮且点了不动，另一端是链接。
 * href 即使 JS 没跑起来也能用：电脑版方向带 ?desktop=1，index.html 的 head 会接住。
 * 逻辑在 js/view-switch.js，这里只管长相。 */
.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.view-switch-btn {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-3);
  transition: color 0.15s, background 0.15s;
}
.view-switch-btn:hover { color: var(--ink); }
.view-switch-btn.is-on {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  cursor: default;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 6px 5px 14px;
  min-width: 220px;
}
.search-box input {
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
.search-box input::placeholder { color: var(--ink-3); }
.search-box button {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  /* 按钮的固有宽度（"搜索"两字 + 内边距）比它在窄搜索框里分到的空间大，
     不给这两条的话文字会折成两行、按钮被撑成 48×52 的竖条。
     要让位就让 input 让 —— 它本来就有 min-width: 0。 */
  white-space: nowrap;
  flex: none;
}

/* ------------------------------------------------------------------ 通用 */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
}
.btn:hover { border-color: rgba(0, 0, 0, 0.22); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.hint { color: var(--ink-2); font-size: 13px; }
.hidden { display: none !important; }

.msg {
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--card);
}
.msg.err { border-color: #e6c4bf; background: #fbeeec; color: #7d2b21; }
.msg.ok { border-color: #bfdcd1; background: var(--accent-soft); color: #14503f; }

/* ------------------------------------------------------------------ 卡片流 */
.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 28px 0 14px;
}
.section-title h1 { font-size: 16px; font-weight: 600; margin: 0; }
.section-title .count { color: var(--ink-3); font-size: 13px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 132px;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card h2 {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.5;
  margin: 0;
  /* 标题最多两行 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .meta {
  margin-top: auto;
  color: var(--ink-2);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}
.card .badge {
  align-self: flex-start;
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 9px;
}
.card .badge.warn { color: #8a4b12; background: #fbf0e2; }
.card .badge.err { color: var(--danger); background: #fbeeec; }

/* 广告位占位（第一期只留位置，不接联盟） */
.card.sponsor {
  border-style: dashed;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  font-size: 12.5px;
  background: transparent;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-2);
}

.pager { display: flex; justify-content: center; gap: 10px; margin-top: 24px; }

/* ------------------------------------------------------------------ 上传区 */
.upload-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 16px 18px;
  margin-top: 12px;
}
.upload-panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  list-style: none;
}
.upload-panel summary::-webkit-details-marker { display: none; }
.upload-panel summary::before { content: "＋ "; color: var(--accent); }
.upload-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; color: var(--ink-2); }
.field input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  background: #fff;
  outline: 0;
}
.field input:focus { border-color: var(--accent); }
.upload-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* 已选文件清单（批量上传时先给一眼确认，避免选错） */
.file-list {
  grid-column: 1 / -1;
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12.5px;
}
.file-list-head {
  position: sticky;
  top: 0;
  padding: 6px 10px;
  color: var(--ink-2);
  background: #f7f6f3;
  border-bottom: 1px solid var(--line);
}
.file-list li:not(.file-list-head) {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
}
.file-list li:last-child { border-bottom: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { flex: none; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* 批量上传的结果汇总 */
.upload-report {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 12px;
  font-size: 12.5px;
}
.report-summary { font-weight: 600; }
.report-summary.ok { color: var(--accent); }
.report-summary.warn { color: var(--danger); }
.upload-report ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); }
.upload-report li { margin-top: 2px; }

/* ------------------------------------------------------------------ 阅读器 */
.reader-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 243, 240, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.reader-head .wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 56px;
  padding-bottom: 0;
}
.reader-head .title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-head .stats { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }

/* 字体没就绪之前不显示正文 —— 用回退字体先画一遍，看起来是"加载完了"，实际是错的版 */
html:not(.fonts-ready) .pages { visibility: hidden; }

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 22px 0 60px;
}

/* 缩放槽：纸张本身尺寸不变，靠 transform 适配窄屏，避免影响任何尺寸计算 */
.page-slot {
  width: calc(var(--paper-w) * var(--zoom, 1));
  height: calc(var(--paper-h) * var(--zoom, 1));
}
.page-slot .pdf-page {
  transform: scale(var(--zoom, 1));
  transform-origin: top left;
  box-shadow: var(--shadow);
  border-radius: 3px;
}

/* 第 N 页起被锁住 */
.lock {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 24px;
  text-align: center;
  max-width: 420px;
}
.lock h3 { margin: 0 0 8px; font-size: 15px; }
.lock p { margin: 0 0 16px; color: var(--ink-2); font-size: 13px; }
.lock .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* a 标签当按钮用时需要显式 display —— 否则 padding 不生效、点不到边距 */
.lock .actions a.btn { display: inline-block; text-decoration: none; }

.lock .email-form {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  width: 100%;
}
.lock .email-form input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  background: #fff;
  outline: 0;
  flex: 1;
  min-width: 0;
  max-width: 220px;
}
.lock .email-form input:focus { border-color: var(--accent); }

.lock .unlock-result { margin-top: 14px; }
/* 覆盖 .lock p 的默认下边距，否则结果区会被撑得很散 */
.lock .unlock-result p { margin: 0 0 10px; }
.lock .ok-line { color: var(--accent); font-size: 13px; }
.lock .err-line { color: var(--danger); font-size: 13px; }

/* 导出档位选择。两个版式的差别不小（纸宽、字号都不同），只写个名字不够 ——
   把尺寸和页数摆在按钮上，不用点开就知道自己在选什么。
   页数来自服务端重排的结果，所以按钮会有一瞬间显示「正在读取」。 */
.lock .profile-tabs {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.lock .profile-tab {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  min-width: 118px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.lock .profile-tab strong { font-size: 13px; font-weight: 500; color: var(--ink); }
.lock .profile-tab em { font-style: normal; font-size: 11.5px; color: var(--ink-3); }
.lock .profile-tab:hover { border-color: rgba(0, 0, 0, 0.22); }
.lock .profile-tab.on { border-color: var(--accent); background: var(--accent-soft); }
.lock .profile-tab.on strong { color: #14503f; }
.lock .profile-tabs .hint { margin: 0; }

/* 广告位占位：第一期只留位置与文案，不接任何广告联盟 */
.sponsor-slot {
  max-width: 720px;
  margin: 24px auto 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 12.5px;
}

.fingerprint {
  max-width: 720px;
  margin: 0 auto 20px;
  color: var(--ink-3);
  font-size: 12px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.fingerprint.bad { color: var(--danger); }

/* ==========================================================================
   下载浮层
   全局只有一个：顶栏按钮与页尾按钮打开的是同一份，档位 / 票据 / 解锁结果
   因此只有一份状态。页尾不再内嵌第二份面板。
   ========================================================================== */

/* .btn 之类的规则会把 display 改掉，hidden 属性就失效了；
   这里兜住，让「隐藏」始终是真的隐藏 */
[hidden] { display: none !important; }

/* 顶栏常驻入口：文章再长也不用翻到结尾才能下载 */
.dl-top { flex: none; white-space: nowrap; }

body.dl-open { overflow: hidden; }

.dl-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 20, 16, 0.42);
  backdrop-filter: blur(2px);
}
.dl-modal.open { display: flex; }

.dl-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 26px 24px 24px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}

/* 面板本身已经是白卡片 —— 里面的 .lock 不能再套一层卡片（边框 + 内边距会翻倍） */
.dl-body .lock {
  max-width: none;
  padding: 0;
  border: 0;
  background: none;
}

.dl-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  font-size: 20px;
  line-height: 1;
}
.dl-close:hover { background: var(--bg); color: var(--ink); }

/* 页尾转化位：读完那一刻最想下载，留一个按钮，但不再堆一整块面板 */
.lock.download.cta { margin-top: 28px; }

@media (max-width: 640px) {
  .search-box { min-width: 0; }
  .brand { font-size: 14px; }
  .dl-top { padding: 5px 10px; font-size: 12.5px; }
}
