/* ===================================================================
   教材库 — 纸感图书馆风格
   =================================================================== */

:root {
  --paper: #fbf9f3;
  --paper-2: #f4f1e8;
  --card: #ffffff;
  --ink: #1b1a16;
  --ink-2: #55524a;
  --ink-3: #8c887d;
  --line: #e5e0d3;
  --line-2: #efece3;
  --accent: #1f5e4a;
  --accent-2: #2c7a61;
  --accent-wash: #eaf1ec;
  --gold: #b08a3a;
  --shadow: 0 1px 2px rgba(40, 36, 25, 0.04), 0 8px 24px rgba(40, 36, 25, 0.06);
  --shadow-lg: 0 18px 50px rgba(40, 36, 25, 0.14);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", STSong, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
}

[data-theme="dark"] {
  --paper: #131311;
  --paper-2: #1a1a17;
  --card: #1d1d19;
  --ink: #ece8dd;
  --ink-2: #a8a397;
  --ink-3: #7a7568;
  --line: #2e2d27;
  --line-2: #26251f;
  --accent: #7cc3a4;
  --accent-2: #9ad6bb;
  --accent-wash: #1c2a24;
  --gold: #cfa858;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 10px;
}
body.is-reading { overflow: hidden; }
a { color: inherit; }
button { font-family: inherit; }
::selection { background: var(--accent); color: #fff; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 20px;
  height: 64px; padding: 0 max(20px, calc((100vw - 1280px) / 2 + 20px));
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex: none; }
.brand .mark {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fdfaf1;
  font-family: var(--serif); font-size: 17px; font-weight: 700;
}
.brand-text { font-family: var(--serif); font-size: 1.06rem; font-weight: 700; letter-spacing: .04em; }
.brand-text i {
  display: block; font-family: var(--mono); font-style: normal;
  font-size: .58rem; letter-spacing: .22em; color: var(--ink-3); text-transform: uppercase;
}
.top-search {
  flex: 1 1 auto; max-width: 560px; position: relative; display: flex; align-items: center;
}
.top-search svg { position: absolute; left: 13px; width: 17px; height: 17px; color: var(--ink-3); pointer-events: none; }
.top-search input {
  width: 100%; height: 40px; padding: 0 42px 0 38px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); font-size: .92rem; font-family: inherit;
  transition: border-color .18s, box-shadow .18s;
}
.top-search input::placeholder { color: var(--ink-3); }
.top-search input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}
.top-search kbd {
  position: absolute; right: 12px; font-family: var(--mono); font-size: .68rem;
  color: var(--ink-3); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; background: var(--paper-2);
}
.top-actions { display: flex; align-items: center; gap: 6px; flex: none; margin-left: auto; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 11px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  font-size: .84rem; text-decoration: none;
  transition: background .16s, color .16s, border-color .16s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); border-color: var(--line); }
.icon-btn b {
  font-family: var(--mono); font-size: .68rem; font-weight: 600;
  background: var(--accent-wash); color: var(--accent);
  border-radius: 20px; padding: 1px 6px; min-width: 18px; text-align: center;
}

/* ---------------- Hero ---------------- */
.hero {
  position: relative; overflow: hidden;
  padding: 66px max(20px, calc((100vw - 1280px) / 2 + 20px)) 54px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 40px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(700px 260px at 88% -30%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    radial-gradient(400px 200px at 6% 110%, color-mix(in srgb, var(--gold) 8%, transparent), transparent 70%),
    var(--paper);
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(90deg, color-mix(in srgb, var(--ink) 4%, transparent) 0 1px, transparent 1px 52px);
  mask-image: linear-gradient(180deg, rgba(0,0,0,.55), transparent 88%);
}
.hero-inner { position: relative; z-index: 1; max-width: 640px; }
.eyebrow {
  margin: 0 0 14px; font-family: var(--mono); font-size: .68rem;
  letter-spacing: .26em; text-transform: uppercase; color: var(--accent);
}
.hero h1 {
  margin: 0 0 14px;
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(2rem, 4.4vw, 3.05rem); line-height: 1.24; letter-spacing: .02em;
}
.lede { margin: 0 0 8px; color: var(--ink-2); font-size: 1rem; max-width: 30em; }
.lede b { font-family: var(--serif); color: var(--ink); font-size: 1.06em; }
.lede-sub { margin: 0; color: var(--ink-3); font-size: .88rem; }
.lede-sub b { color: var(--accent); font-weight: 600; }

/* ---------------- 分类导航 ---------------- */
.catnav {
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(560px 200px at 96% 0%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 70%),
    var(--paper-2);
  padding: 26px max(20px, calc((100vw - 1280px) / 2 + 20px)) 24px;
}
.cat-inner { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.cat-row { display: grid; grid-template-columns: 76px 1fr; gap: 14px; align-items: start; }
.cat-head { display: flex; align-items: baseline; gap: 8px; padding-top: 7px; }
.cat-label {
  font-family: var(--serif); font-weight: 700; font-size: .98rem; letter-spacing: .2em;
  color: var(--ink); position: relative; padding-left: 12px; white-space: nowrap;
}
.cat-label::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 4px; height: 15px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--gold));
}
.cat-hint {
  align-self: center; font-size: .72rem; color: var(--ink-3);
  white-space: nowrap; padding: 0 4px 0 2px;
}
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chip {
  cursor: pointer; border: 1px solid var(--line); background: var(--card);
  color: var(--ink-2); border-radius: 999px; padding: 6px 14px;
  font-size: .85rem; line-height: 1.5; font-family: inherit;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  transition: border-color .16s, color .16s, background .16s, transform .16s, box-shadow .16s;
}
.cat-chip:hover {
  border-color: var(--accent); color: var(--accent);
  transform: translateY(-1px); box-shadow: var(--shadow);
}
.cat-chip .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  background: var(--c, var(--ink-3));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.cat-chip i {
  font-style: normal; font-family: var(--mono); font-size: .66rem;
  color: var(--ink-3); transform: translateY(-.5px);
}
.cat-chip.on {
  background: var(--accent); border-color: var(--accent); color: #fdfaf1;
  font-weight: 500; box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 55%, transparent);
}
[data-theme="dark"] .cat-chip.on { color: #10201a; }
.cat-chip.on .dot { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .45); }
.cat-chip.on i { color: inherit; opacity: .75; }

/* ---------------- 筛选条 ---------------- */
.filters {
  position: sticky; top: 64px; z-index: 30;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 11px max(20px, calc((100vw - 1280px) / 2 + 20px));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.crumbs { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; flex: 1 1 auto; min-height: 32px; }
.crumb-hint { font-size: .78rem; color: var(--ink-3); }
.crumb {
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  background: var(--accent-wash); color: var(--accent);
  border-radius: 999px; padding: 4px 7px 4px 12px; font-size: .78rem;
  transition: background .16s, border-color .16s;
}
.crumb b { font-weight: 500; }
.crumb b::before { content: attr(data-k); font-size: .68rem; opacity: .65; margin-right: 5px; }
.crumb i {
  font-style: normal; width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center; font-size: .72rem; line-height: 1;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  transition: background .16s, color .16s;
}
.crumb:hover i { background: var(--accent); color: #fdfaf1; }
.hero-side { position: relative; z-index: 1; text-align: right; flex: none; padding-bottom: 6px; }
.stamp {
  display: inline-flex; align-items: baseline; gap: 8px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
  background: var(--card); box-shadow: var(--shadow);
}
.stamp-line { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stamp-label { font-size: .74rem; color: var(--ink-3); letter-spacing: .1em; }
.stamp-note { margin: 10px 0 0; font-size: .72rem; color: var(--ink-3); line-height: 1.7; }

.filter-right { display: flex; align-items: center; gap: 8px; flex: none; }
.sel { display: inline-flex; align-items: center; gap: 6px; }
.sel > span { font-size: .74rem; color: var(--ink-3); }
.sel select {
  height: 32px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font-family: inherit; font-size: .82rem;
  padding: 0 6px; cursor: pointer; max-width: 150px;
}
.sel select:focus { outline: none; border-color: var(--accent); }
.count { font-family: var(--mono); font-size: .74rem; color: var(--ink-3); padding-left: 4px; }
.reset {
  cursor: pointer; border: 0; background: transparent; color: var(--accent);
  font-size: .78rem; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------------- 网格与卡片 ---------------- */
main {
  max-width: 1280px; margin: 0 auto; padding: 30px 20px 60px;
}
.grid {
  display: grid; gap: 20px 18px;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
}
.card {
  position: relative; text-align: left; cursor: pointer;
  border: 0; background: transparent; padding: 0; color: inherit;
  display: flex; flex-direction: column; gap: 10px;
  animation: pop .35s cubic-bezier(.2, .7, .2, 1) backwards;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.cover {
  position: relative; aspect-ratio: 4 / 5; width: 100%; overflow: hidden;
  border-radius: 4px 9px 9px 4px;
  background: linear-gradient(155deg, var(--c), color-mix(in srgb, var(--c) 62%, #10100c));
  box-shadow: 0 2px 4px rgba(30, 26, 18, .16), 0 12px 26px -12px rgba(30, 26, 18, .4);
  transition: transform .26s cubic-bezier(.2, .7, .2, 1), box-shadow .26s;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 14px 13px 12px 19px;
}
.card:hover .cover { transform: translateY(-5px) rotate(-.5deg); box-shadow: 0 6px 10px rgba(30, 26, 18, .2), 0 22px 40px -14px rgba(30, 26, 18, .45); }
/* 书脊 */
.cover::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .38), rgba(255, 255, 255, .1));
}
/* 纸纹 */
.cover::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 3px);
}
.cover-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.cover-stage {
  font-size: .6rem; letter-spacing: .12em; color: rgba(255, 255, 255, .78);
  border: 1px solid rgba(255, 255, 255, .28); border-radius: 3px; padding: 1px 5px;
  backdrop-filter: blur(2px);
}
.cover-subject {
  font-family: var(--serif); font-weight: 700; color: #fdfaf1;
  font-size: 1.28rem; line-height: 1.15; letter-spacing: .16em;
  writing-mode: vertical-rl; text-shadow: 0 2px 10px rgba(0, 0, 0, .28);
  max-height: 74%; overflow: hidden;
}
.cover-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; }
.cover-pub {
  font-size: .62rem; color: rgba(255, 255, 255, .72); letter-spacing: .04em;
  max-width: 74%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cover-size { font-family: var(--mono); font-size: .6rem; color: rgba(255, 255, 255, .6); }
.card-body { display: flex; flex-direction: column; gap: 3px; }
.card-title {
  font-size: .86rem; line-height: 1.45; color: var(--ink); font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.5em;
}
.card:hover .card-title { color: var(--accent); }
.card-meta {
  font-size: .72rem; color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fav {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 26px; height: 26px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; opacity: 0;
  background: rgba(20, 18, 14, .55); color: #fff;
  backdrop-filter: blur(6px); transition: opacity .18s, transform .18s, background .18s;
}
.fav svg { width: 14px; height: 14px; }
.card:hover .fav { opacity: 1; }
.fav:hover { transform: scale(1.1); background: rgba(20, 18, 14, .78); }
.fav.on { opacity: 1; background: var(--gold); color: #fffdf6; }
.fav.on svg { fill: currentColor; }

.more { display: flex; justify-content: center; padding: 44px 0 10px; }
.more[hidden] { display: none; }
.more button {
  cursor: pointer; border: 1px solid var(--line); background: var(--card);
  color: var(--ink-2); border-radius: 10px; padding: 11px 30px; font-size: .86rem;
  transition: all .18s; box-shadow: var(--shadow);
}
.more button:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }

.empty { text-align: center; padding: 90px 0; }
.empty-big { font-family: var(--serif); font-size: 1.3rem; margin: 0 0 6px; }
.empty-sub { color: var(--ink-3); font-size: .86rem; margin: 0; }

/* ---------------- 页脚 ---------------- */
footer {
  border-top: 1px solid var(--line); background: var(--paper-2);
  padding: 30px 20px 40px; margin-top: 20px;
}
.foot-inner { max-width: 1280px; margin: 0 auto; }
footer p { margin: 0 0 8px; font-size: .8rem; color: var(--ink-2); line-height: 1.8; }
footer p.muted { color: var(--ink-3); font-size: .76rem; max-width: 72em; }
footer a { color: var(--accent); text-underline-offset: 3px; }

/* ---------------- 阅读器 ---------------- */
.reader {
  position: fixed; inset: 0; z-index: 90; background: var(--paper-2);
  display: flex; flex-direction: column;
  animation: readerIn .26s ease-out;
}
.reader[hidden] { display: none; }
@keyframes readerIn { from { opacity: 0; transform: scale(.995); } to { opacity: 1; transform: none; } }
.reader-bar {
  flex: none; display: flex; align-items: center; gap: 14px;
  height: 56px; padding: 0 14px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.rbtn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-2);
  font-size: .82rem; text-decoration: none; flex: none; transition: all .16s;
}
.rbtn svg { width: 15px; height: 15px; }
.rbtn:hover { border-color: var(--accent); color: var(--accent); }
.rbtn.primary { background: var(--accent); border-color: var(--accent); color: #fdfaf1; }
[data-theme="dark"] .rbtn.primary { color: #10201a; }
.rbtn.primary:hover { filter: brightness(1.06); color: #fdfaf1; }
.rbtn.on { background: var(--gold); border-color: var(--gold); color: #fffdf6; }
.r-title { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; line-height: 1.3; }
.r-title b {
  font-size: .92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.r-title span { font-size: .72rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-actions { display: flex; gap: 6px; flex: none; }
.reader-body { position: relative; flex: 1 1 auto; background: #454239; overflow: hidden; }
[data-theme="dark"] .reader-body { background: #0c0c0a; }
.page-wrap {
  position: absolute; inset: 0; overflow: auto;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 22px 16px 40px;
}
#pdfCanvas {
  display: block; background: #fff; border-radius: 3px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35), 0 20px 60px rgba(0, 0, 0, .3);
}
.reader-loading {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: var(--paper-2); color: var(--ink-2);
}
.reader-loading[hidden] { display: none; }
.reader-loading p { margin: 0; font-size: .88rem; }
.reader-loading .tip { font-size: .76rem; color: var(--ink-3); }
.reader-loading.error .spinner { display: none; }
.pbar {
  width: 240px; height: 4px; border-radius: 2px; overflow: hidden;
  background: var(--line);
}
.pbar i {
  display: block; height: 100%; width: 0; border-radius: 2px;
  background: var(--accent); transition: width .25s ease;
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.r-pager {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
}
.pg-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink-2); cursor: pointer; font-size: 1rem;
  line-height: 1; transition: all .16s;
}
.pg-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pg-btn:disabled { opacity: .4; cursor: default; }
.r-pager input {
  width: 44px; height: 30px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font-family: var(--mono); font-size: .8rem;
}
.r-pager input:focus { outline: none; border-color: var(--accent); }
.pg-total { font-family: var(--mono); font-size: .74rem; color: var(--ink-3); }
.pg-total b { font-weight: 500; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1080px) {
  .hero-side { display: none; }
}
@media (max-width: 860px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .top-search { order: 3; max-width: none; flex-basis: 100%; }
  .filters { top: 0; position: static; padding: 10px 16px; gap: 10px; }
  .filter-right { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .catnav { padding: 20px 16px 18px; }
  .cat-inner { gap: 14px; }
  .cat-row { grid-template-columns: 1fr; gap: 8px; }
  .cat-head { padding-top: 0; }
  .cat-chips { gap: 7px; }
  .cat-chip { padding: 5px 12px; font-size: .82rem; }
  .hero { padding: 40px 16px 34px; }
  .hero h1 { font-size: 1.8rem; }
  main { padding: 22px 16px 50px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 12px; }
  .cover { padding: 11px 10px 10px 15px; }
  .cover-subject { font-size: 1.05rem; }
  .reader-bar { height: auto; flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .r-title { flex-basis: calc(100% - 90px); order: 2; }
  .r-actions { order: 3; flex-basis: 100%; overflow-x: auto; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .icon-btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
