/* ===== Цахим номын сан ===== */
.lib-tools { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: 1.2rem; }
.lib-search { position: relative; flex: 1 1 320px; max-width: 460px; }
.lib-search svg { position: absolute; left: 1rem; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.lib-search input {
  width: 100%; font: inherit; padding: .85rem 1rem .85rem 2.8rem; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); transition: border-color .2s, box-shadow .2s;
}
.lib-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.lib-cats { display: flex; flex-wrap: wrap; gap: .5rem; }
.lib-cat {
  font: inherit; font-weight: 700; font-size: .9rem; padding: .5rem 1rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); transition: .2s;
}
.lib-cat span { color: var(--muted); font-weight: 600; margin-left: .2rem; }
.lib-cat:hover { border-color: var(--primary); color: var(--primary); }
.lib-cat.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.lib-cat.is-active span { color: #c9d0f5; }
.lib-count { color: var(--muted); font-weight: 700; font-size: .9rem; margin: 0 0 1.2rem; min-height: 1.4em; }

.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2rem 1.5rem; }
.book { display: flex; flex-direction: column; gap: .9rem; }
.book__cover {
  position: relative; aspect-ratio: 3 / 4.2; border-radius: 6px 14px 14px 6px; overflow: hidden; background: var(--primary-soft);
  box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 16px 30px -18px rgba(27,36,100,.55);
  transition: transform .3s ease, box-shadow .3s ease;
}
.book__cover::before { /* номын нуруу */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 10px; z-index: 2;
  background: linear-gradient(90deg, rgba(0,0,0,.22), rgba(255,255,255,.12) 60%, transparent);
}
.book__cover img { width: 100%; height: 100%; object-fit: cover; }
.book__read {
  position: absolute; left: 50%; bottom: 1rem; transform: translate(-50%, 10px); opacity: 0; z-index: 3;
  background: var(--gold); color: #fff; font-weight: 800; font-size: .85rem; padding: .45rem 1.1rem; border-radius: 999px;
  transition: .25s; box-shadow: 0 8px 18px -8px rgba(214,66,10,.8);
}
.book:hover .book__cover, .book:focus-visible .book__cover { transform: translateY(-6px); box-shadow: 0 26px 40px -20px rgba(27,36,100,.6); }
.book:hover .book__read, .book:focus-visible .book__read { opacity: 1; transform: translate(-50%, 0); }
.book__gen {
  height: 100%; display: flex; flex-direction: column; justify-content: space-between; gap: 1rem; padding: 1.4rem 1.1rem 1.2rem 1.5rem; color: #fff;
  background:
    radial-gradient(120% 70% at 100% 0%, hsl(calc(var(--h) + 40) 70% 60% / .55), transparent 60%),
    linear-gradient(160deg, hsl(var(--h) 55% 34%), hsl(calc(var(--h) + 25) 60% 20%));
}
.book__gen-title { font-weight: 900; font-size: 1.05rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.book__gen-author { font-size: .8rem; font-weight: 700; opacity: .85; border-top: 2px solid rgba(255,255,255,.4); padding-top: .6rem; }
.book__info h3 { font-size: 1rem; margin: 0; line-height: 1.3; transition: color .2s; }
.book:hover .book__info h3 { color: var(--primary); }
.book__info p { margin: .3rem 0 0; color: var(--muted); font-size: .88rem; font-weight: 600; }
.book__info small { color: var(--muted); font-size: .78rem; }
.book__cat { display: inline-block; font-size: .7rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--gold-text); margin-bottom: .3rem; }
@media (max-width: 640px) {
  .books { grid-template-columns: repeat(2, 1fr); gap: 1.5rem 1rem; }
  .book__read { display: none; }
}

/* ===== Уншигч ===== */
html.is-reading, html.is-reading body { overflow: hidden; height: 100%; }
.reader { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; background: #2a2f45; color: #fff; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.reader__bar {
  display: flex; align-items: center; gap: 1rem; padding: .55rem 1rem; min-height: 60px;
  background: var(--primary-dark); border-bottom: 3px solid var(--gold); box-shadow: 0 6px 20px -10px rgba(0,0,0,.6);
}
.reader__btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-width: 38px; height: 38px; padding: 0 .55rem;
  border: 0; border-radius: 10px; background: rgba(255,255,255,.08); color: #fff; font: inherit; font-weight: 800; font-size: 1.1rem; cursor: pointer; transition: background .2s;
}
.reader__btn:hover { background: rgba(255,255,255,.18); }
.reader__btn svg { width: 20px; height: 20px; }
.reader__back { font-size: .9rem; padding-right: .9rem; }
.reader__title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.reader__title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader__title small { color: #aeb8e6; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader__controls { display: flex; align-items: center; gap: .75rem; }
.reader__pager, .reader__zoom { display: flex; align-items: center; gap: .35rem; }
.reader__pager input {
  width: 3.4em; height: 38px; text-align: center; font: inherit; font-weight: 800; color: #fff;
  background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.15); border-radius: 10px;
}
.reader__pager input:focus { outline: none; border-color: var(--gold); }
.reader__pager span { color: #c9d0f5; font-size: .9rem; white-space: nowrap; }
.reader__pct { font-size: .85rem; min-width: 58px; }
.reader__progress { height: 3px; background: rgba(255,255,255,.08); }
.reader__progress span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .1s linear; }
.reader__body { position: relative; flex: 1; overflow: auto; overscroll-behavior: contain; padding: 16px 0 40px; }
.reader__pages { display: flex; flex-direction: column; align-items: center; gap: 14px; width: max-content; min-width: 100%; padding: 0 16px; }
.rpage { position: relative; background: #fff; box-shadow: 0 10px 30px -12px rgba(0,0,0,.6); flex-shrink: 0; }
.rpage canvas { position: relative; z-index: 1; display: block; width: 100%; height: 100%; pointer-events: none; }
.rpage__num { position: absolute; inset: 0; display: grid; place-items: center; color: #c5cae0; font-weight: 800; font-size: 1.4rem; }
.reader__status { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 1rem; text-align: center; padding: 2rem; color: #dfe3f8; font-weight: 700; z-index: 2; }
.reader__status p { margin: 0; font-size: 1.05rem; }
.reader:fullscreen { background: #2a2f45; }

@media (max-width: 760px) {
  .reader__bar { flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; }
  .reader__back span { display: none; }
  .reader__back { padding-right: .55rem; }
  .reader__title { order: 0; flex: 1; }
  .reader__controls { order: 1; width: 100%; justify-content: space-between; }
  #r-full { display: none; }
}

/* Хэвлэхийг хаана */
@media print {
  html.is-reading body * { display: none !important; }
  html.is-reading body::after { content: "Цахим номыг хэвлэх боломжгүй."; display: block; padding: 2rem; font: 700 18px sans-serif; }
}

@media (max-width: 480px) {
  #library .header .btn--ghost { padding: .55em .9em; font-size: .82rem; }
  #library .logo__text { font-size: .88rem; max-width: 170px; }
}
