@import url('https://fonts.googleapis.com/css2?family=Literata:opsz,wght@7..72,400;7..72,600;7..72,700&display=swap');

/* ==========================================================================
   ПЕКАРНЯ LIBRARY — Night Stack
   Тёмно-серый читальный зал: полки, корешки, открытие тома.
   Бекап прежней темы: wiki.css.bak
   ========================================================================== */

@font-face {
  font-family: 'Benzin';
  src: local('Benzin Medium'), local('Benzin-Medium'),
       url('/fonts/Benzin/Benzin-Medium.woff2') format('woff2'),
       url('/fonts/Benzin/Benzin-Medium.woff') format('woff'),
       url('/fonts/Benzin/Benzin-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #101214;
  --bg-2: #16181c;
  --bg-3: #1e2126;
  --surface: #1a1c20;
  --shelf: #141618;
  --text: #e8e6e3;
  --text-muted: #9a9690;
  --accent: #c9a66b;
  --accent-hover: #e0c08a;
  --accent-deep: #8a6d3d;
  --glow: rgba(201, 166, 107, 0.22);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --card-bg: #191b1f;
  --code-bg: rgba(255, 255, 255, 0.04);
  --paper: #ece7de;
  --paper-ink: #1c1915;
  --danger: #e58b8b;
  --ok: #7dcb9a;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  --side-w: 268px;
  --toc-w: 220px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --header-h: 60px;
}

[data-theme='light'] {
  --bg: #ebe7e0;
  --bg-2: #f5f2ec;
  --bg-3: #fffdf9;
  --surface: #ffffff;
  --shelf: #e4dfd6;
  --text: #1c1915;
  --text-muted: #6b655c;
  --accent: #8a6d3d;
  --accent-hover: #6e552e;
  --accent-deep: #5c4728;
  --glow: rgba(138, 109, 61, 0.18);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --card-bg: #ffffff;
  --code-bg: rgba(0, 0, 0, 0.04);
  --paper: #ffffff;
  --paper-ink: #1c1915;
  --shadow: 0 14px 36px rgba(40, 32, 20, 0.12);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body.lib {
  margin: 0;
  min-height: 100vh;
  font-family: 'Benzin', system-ui, 'Segoe UI', sans-serif;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(201, 166, 107, 0.07), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(255, 255, 255, 0.03), transparent 45%),
    linear-gradient(180deg, #121416 0%, var(--bg) 40%, #0c0d0f 100%);
  color: var(--text);
  line-height: 1.7;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
[data-theme='light'] body.lib {
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(201, 166, 107, 0.12), transparent 50%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
::selection { background: var(--accent); color: #1a140c; }

kbd {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px; padding: 2px 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text-muted);
}

.lib-muted { color: var(--text-muted); font-size: 13px; }
.lib-lead { margin: 0 0 18px; max-width: 68ch; color: var(--text-muted); font-size: 15px; line-height: 1.65; }

/* ------------------------------ boot splash ------------------------------ */

.lib-boot {
  position: fixed; inset: 0; z-index: 10000;
  display: grid; place-items: center;
  background: #050506;
  color: #efeae2;
  transition: opacity 0.7s var(--ease), visibility 0.7s;
}
.lib-boot.is-done {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.lib-boot-inner {
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  animation: bootRise 1.1s var(--ease) both;
}
.lib-boot-book {
  width: 88px; height: 72px; position: relative;
  transform-style: preserve-3d;
  animation: bootPulse 1.8s ease-in-out infinite;
}
.lib-boot-cover,
.lib-boot-page {
  position: absolute; inset: 0;
  border-radius: 3px 8px 8px 3px;
  transform-origin: left center;
}
.lib-boot-cover {
  background: linear-gradient(145deg, #2a241c, #16130f 55%, #0d0b09);
  border: 1px solid rgba(201, 166, 107, 0.35);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 20px 50px rgba(0,0,0,0.55), 0 0 40px rgba(201,166,107,0.12);
}
.lib-boot-cover::after {
  content: '';
  position: absolute; left: 10px; top: 14px; bottom: 14px; width: 2px;
  background: linear-gradient(180deg, transparent, var(--accent), transparent);
  opacity: 0.7;
}
.lib-boot-page {
  inset: 4px 4px 4px 8px;
  background: linear-gradient(90deg, #d8d2c6, #f0ebe2);
  transform: rotateY(-8deg);
  animation: bootOpen 1.6s var(--ease) 0.35s both;
}
.lib-boot-mark {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 28px; z-index: 2; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
}
.lib-boot-word {
  font-size: 13px; letter-spacing: 0.42em; text-indent: 0.42em;
  text-transform: uppercase; color: rgba(239, 234, 226, 0.82);
  animation: bootFade 1s ease 0.55s both;
}
.lib-boot-sub {
  font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  color: rgba(201, 166, 107, 0.75);
  animation: bootFade 1s ease 0.85s both;
}
.lib-boot-line {
  width: 56px; height: 1px; margin-top: -8px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: bootLine 1.2s ease 0.7s both;
}

@keyframes bootRise {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes bootPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes bootOpen {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(-28deg); }
}
@keyframes bootFade {
  from { opacity: 0; letter-spacing: 0.55em; }
  to { opacity: 1; }
}
@keyframes bootLine {
  from { transform: scaleX(0); opacity: 0; }
  to { transform: scaleX(1); opacity: 1; }
}

html.lib-boot-pending body.lib { overflow: hidden; }
html.lib-boot-pending body.lib > :not(.lib-boot) { visibility: hidden; }
body.lib.is-booting { overflow: hidden; }
body.lib.is-booting > :not(.lib-boot) { visibility: hidden; }
.lib-boot[hidden] { display: none !important; }

/* ------------------------------ каркас ----------------------------------- */

.lib-shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  align-items: start;
}

.lib-main {
  min-width: 0;
  padding: 28px 44px 88px;
  max-width: 1180px;
  margin: 0 auto;
  animation: pageIn 0.55s var(--ease) both;
}
.lib-main-article { max-width: 1280px; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 1400px) {
  .lib-main-article {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--toc-w);
    gap: 34px;
    align-items: start;
  }
  .lib-main-article .lib-crumbs,
  .lib-main-article .lib-article { grid-column: 1; }
  .lib-main-article .lib-toc { grid-column: 2; grid-row: 1 / span 2; position: sticky; top: 84px; }
}

/* ------------------------------ хедер ------------------------------------ */

.lib-header {
  position: sticky; top: 0; z-index: 900;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px) saturate(1.1);
  border-bottom: 1px solid var(--border);
}
[data-theme='light'] .lib-header { background: rgba(245, 242, 236, 0.88); }

.lib-header-inner {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; min-height: var(--header-h);
}

.lib-brand {
  display: flex; align-items: center; gap: 5px;
  font-size: 16px; font-weight: 900; letter-spacing: 1.2px; white-space: nowrap;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; object-fit: cover; margin-right: 6px;
  box-shadow: 0 0 0 1px rgba(201,166,107,0.25), 0 6px 16px rgba(0,0,0,0.35);
}
.lib-brand .b-white { color: var(--text); }
.lib-brand .b-accent { color: var(--accent); }
.lib-brand .b-tag {
  margin-left: 8px; font-size: 9px; letter-spacing: 2px; padding: 3px 8px; border-radius: 999px;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}

.lib-topnav { display: flex; gap: 2px; }
.lib-topnav a {
  padding: 7px 12px; border-radius: var(--radius-xs); font-size: 13px; color: var(--text-muted);
  transition: color 0.18s, background 0.18s;
}
.lib-topnav a:hover { color: var(--text); background: var(--bg-3); }
.lib-topnav a.is-active { color: var(--text); background: var(--bg-3); box-shadow: inset 0 -2px 0 var(--accent); }

.lib-search-trigger {
  flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 460px;
  padding: 9px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text-muted); font-family: inherit; font-size: 13px; cursor: pointer;
  transition: border-color 0.18s, color 0.18s, box-shadow 0.18s;
}
.lib-search-trigger:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--text); box-shadow: 0 0 0 3px var(--glow);
}
.lib-search-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-search-trigger kbd { margin-left: auto; flex-shrink: 0; }
.lib-search-trigger svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }

.lib-header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.lib-user {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-3); font-size: 12px; color: var(--text);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-user-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); flex-shrink: 0; }

.lib-burger {
  display: none; flex-direction: column; gap: 4px; width: 36px; height: 36px; padding: 9px;
  border-radius: var(--radius-xs); border: 1px solid var(--border); background: var(--bg-3); cursor: pointer;
}
.lib-burger span { display: block; height: 2px; background: var(--text); border-radius: 2px; }

/* ------------------------------ кнопки ----------------------------------- */

.lib-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border: 1px solid transparent; border-radius: var(--radius-xs);
  font-family: inherit; font-size: 12px; font-weight: 900; letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap; cursor: pointer; color: #1a140c;
  background: linear-gradient(165deg, var(--accent-hover), var(--accent) 45%, var(--accent-deep));
  box-shadow: 0 8px 22px var(--glow);
  transition: transform 0.18s var(--ease), filter 0.18s;
}
.lib-btn:hover { transform: translateY(-2px); filter: brightness(1.06); }
.lib-btn.ghost { background: transparent; color: var(--text-muted); border-color: var(--border); box-shadow: none; }
.lib-btn.ghost:hover { color: var(--text); border-color: var(--border-strong); }
.lib-btn.icon { padding: 9px 11px; }
.lib-btn.sm { padding: 6px 10px; font-size: 11px; }
.lib-btn.ghost.danger:hover { color: var(--danger); border-color: rgba(229, 139, 139, 0.45); }
[data-theme='light'] .lib-btn { color: #fff; }
.ico-sun, .ico-moon { font-size: 14px; line-height: 1; }
[data-theme='dark'] .ico-sun { display: none; }
[data-theme='light'] .ico-moon { display: none; }

/* ----------------------------- сайдбар ----------------------------------- */

.lib-side {
  position: sticky; top: var(--header-h); align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto; padding: 18px 12px 40px 16px;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.015), transparent 40%),
    color-mix(in srgb, var(--shelf) 92%, transparent);
}
.lib-side::-webkit-scrollbar { width: 5px; }
.lib-side::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

.lib-tree { display: flex; flex-direction: column; gap: 1px; }
.tree-group { margin-top: 12px; }
.tree-link {
  display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: var(--radius-xs);
  font-size: 13px; color: var(--text-muted); border-left: 2px solid transparent;
  transition: color 0.14s, background 0.14s, border-color 0.14s, transform 0.14s;
}
.tree-link:hover { color: var(--text); background: var(--bg-3); transform: translateX(2px); }
.tree-link.is-active { color: var(--text); background: var(--bg-3); border-left-color: var(--accent); }
.tree-link.is-static { pointer-events: none; opacity: 0.65; }
.tree-home, .tree-section { font-weight: 900; color: var(--text); font-size: 12.5px; letter-spacing: 0.2px; }
.tree-folder { color: var(--accent); }
.tree-subsection { padding-left: 16px; font-size: 12.5px; }
.tree-kids { display: flex; flex-direction: column; margin: 1px 0 4px; }
.tree-kids .tree-link { padding-left: 26px; font-size: 12.5px; }
.tree-ico { width: 16px; text-align: center; opacity: 0.85; flex-shrink: 0; }
.tree-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count {
  font-size: 10px; padding: 1px 6px; border-radius: 99px;
  color: var(--text-muted); background: var(--bg-3); border: 1px solid var(--border);
}

/* ------------------------------- герой ----------------------------------- */

.lib-hero {
  position: relative;
  padding: 18px 0 28px;
  margin-bottom: 8px;
}
.lib-hero::before {
  content: '';
  position: absolute; left: -12px; right: -12px; top: 0; bottom: 8px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03), transparent 60%),
    radial-gradient(ellipse at 20% 0%, rgba(201,166,107,0.08), transparent 55%);
  border: 1px solid var(--border);
  pointer-events: none;
}
.lib-hero > * { position: relative; padding-inline: 16px; }
.lib-kicker {
  display: inline-block; font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 10px;
}
.lib-hero h1 {
  margin: 0 0 12px; font-size: clamp(30px, 4.6vw, 50px);
  line-height: 1.05; letter-spacing: -0.8px;
}
.lib-hero h1 span { color: var(--accent); }
.lib-hero-stats { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 10px; }
.lib-stat {
  min-width: 108px; padding: 13px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--card-bg) 88%, transparent);
  backdrop-filter: blur(6px);
  transition: transform 0.2s var(--ease), border-color 0.2s;
}
.lib-stat:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.lib-stat b { display: block; font-size: 24px; line-height: 1.1; color: var(--accent); }
.lib-stat span { font-size: 10.5px; letter-spacing: 1.3px; text-transform: uppercase; color: var(--text-muted); }

/* ---------------------------- заголовки/сетки ---------------------------- */

.lib-h2 { display: flex; align-items: center; gap: 12px; margin: 38px 0 16px; font-size: 18px; }
.lib-h2::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--border-strong), transparent); }
.lib-h2-more { font-size: 12px; color: var(--accent); }
.lib-h2-count {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text-muted);
}
.lib-sub-desc { margin: -6px 0 14px; font-size: 13px; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  perspective: 1200px;
}

/* карточка как том на полке */
.lib-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 18px 18px 18px 22px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background:
    linear-gradient(90deg, rgba(201,166,107,0.14) 0 4px, transparent 4px),
    var(--card-bg);
  overflow: hidden;
  transform-origin: left center;
  transition: transform 0.28s var(--ease), border-color 0.2s, box-shadow 0.28s;
}
.lib-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--accent-hover), var(--accent-deep));
  opacity: 0.85;
}
.lib-card:hover {
  transform: translateY(-6px) rotateY(-4deg) scale(1.01);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: var(--shadow), 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
  z-index: 2;
}
.lib-card.has-cover { padding-top: 0; }
.lib-card.has-cover::before { top: 132px; }
.lib-card-cover {
  display: block; height: 132px; margin: 0 -18px 12px -22px;
  background-size: cover; background-position: center;
  border-bottom: 1px solid var(--border);
  filter: saturate(0.85) brightness(0.92);
  transition: filter 0.3s;
}
.lib-card:hover .lib-card-cover { filter: none; }
.lib-card-ico { font-size: 20px; line-height: 1; }
.lib-card-title { font-size: 15px; font-weight: 900; }
.lib-card-desc {
  font-size: 12.5px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-card-foot {
  margin-top: auto; font-size: 11px; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--accent);
}
.lib-card.is-book {
  background:
    linear-gradient(90deg, rgba(201,166,107,0.22) 0 5px, transparent 5px),
    linear-gradient(160deg, #242128, var(--card-bg));
}
.lib-card.is-book::before { width: 5px; }

/* полка под рядом карточек */
.lib-shelf {
  position: relative;
  padding-bottom: 18px;
  margin-bottom: 8px;
}
.lib-shelf::after {
  content: '';
  position: absolute; left: -4px; right: -4px; bottom: 0; height: 10px;
  border-radius: 2px;
  background:
    linear-gradient(180deg, #2a2d33, #15171a 70%, #0d0e10);
  box-shadow:
    0 8px 16px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

.lib-card.is-opening {
  animation: bookPull 0.45s var(--ease) forwards;
  pointer-events: none;
  z-index: 5;
}
@keyframes bookPull {
  0% { transform: translateY(0) rotateY(0); }
  40% { transform: translateY(-18px) rotateY(-12deg) scale(1.04); }
  100% { transform: translateY(-8px) rotateY(-28deg) scale(1.06); opacity: 0.15; }
}

/* --------------------------- список обновлённых -------------------------- */

.lib-recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.lib-recent li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
  padding: 10px 12px; border-radius: var(--radius-xs);
  transition: background 0.15s, transform 0.15s;
}
.lib-recent li:hover { background: var(--card-bg); transform: translateX(3px); }
.lib-recent .lib-muted { font-size: 11.5px; white-space: nowrap; }

/* -------------------------------- чипы ----------------------------------- */

.lib-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.lib-chips.lg { gap: 10px; }
.lib-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-3); font-size: 12px; color: var(--text-muted);
  transition: color 0.14s, border-color 0.14s, transform 0.14s;
}
.lib-chip:hover { color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }
.lib-chip i { font-style: normal; font-size: 10px; opacity: 0.65; }
.lib-chip.sm { padding: 3px 9px; font-size: 11px; }

/* ------------------------------- крошки ---------------------------------- */

.lib-crumbs {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center;
  font-size: 12px; color: var(--text-muted); margin-bottom: 16px;
}
.lib-crumbs a:hover { color: var(--accent); }
.lib-crumbs b { color: var(--text); font-weight: 500; }
.lib-crumbs span { opacity: 0.5; }

/* ------------------------------ шапка стр. ------------------------------- */

.lib-page-head { margin-bottom: 20px; }
.lib-page-head h1 {
  margin: 0 0 10px; font-size: clamp(25px, 3.4vw, 38px);
  line-height: 1.12; letter-spacing: -0.5px;
}
.lib-page-ico { font-size: 28px; display: block; margin-bottom: 6px; }
.lib-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }
.lib-edit {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border-strong);
  color: var(--accent); font-size: 11px;
}
.lib-edit:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.lib-edit.ghost { border-color: var(--border); color: var(--text-muted); }

/* ------------------------------ обложка статьи --------------------------- */

.lib-cover-head {
  position: relative; margin: 0 0 24px; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
.lib-cover-head img { display: block; width: 100%; max-height: 340px; object-fit: cover; filter: brightness(0.88); }
.lib-cover-overlay {
  position: absolute; inset: auto 0 0 0; padding: 22px 24px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88), rgba(0, 0, 0, 0.2) 70%, transparent);
}
.lib-cover-overlay h1 { margin: 0 0 6px; font-size: clamp(24px, 3.4vw, 38px); color: #fff; }
.lib-cover-overlay p { margin: 0 0 6px; color: rgba(255, 255, 255, 0.82); }
.lib-cover-overlay .lib-muted { color: rgba(255, 255, 255, 0.6); }

/* ----------------------------- контент статьи ---------------------------- */

.lib-article {
  position: relative;
  animation: tomeOpen 0.65s var(--ease) both;
}
@keyframes tomeOpen {
  from { opacity: 0; transform: perspective(900px) rotateY(8deg) translateX(18px); filter: blur(2px); }
  to { opacity: 1; transform: none; filter: none; }
}

.lib-content {
  font-family: 'Literata', Georgia, 'Times New Roman', serif;
  font-size: 16.5px; line-height: 1.82; overflow-wrap: break-word; max-width: 72ch;
  color: color-mix(in srgb, var(--text) 94%, #fff);
}
.lib-content > *:first-child { margin-top: 0; }
.lib-content h1, .lib-content h2, .lib-content h3, .lib-content h4 {
  font-family: 'Benzin', system-ui, sans-serif;
  line-height: 1.25; letter-spacing: -0.2px;
}
.lib-content h1 { font-size: 29px; margin: 34px 0 14px; }
.lib-content h2 {
  font-size: 22px; margin: 36px 0 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border); scroll-margin-top: 80px;
}
.lib-content h3 { font-size: 18px; margin: 26px 0 10px; scroll-margin-top: 80px; }
.lib-content h4 { font-size: 16px; margin: 20px 0 8px; scroll-margin-top: 80px; }
.lib-content p { margin: 0 0 15px; }
.lib-content ul, .lib-content ol { margin: 0 0 16px; padding-left: 24px; }
.lib-content li { margin-bottom: 6px; }
.lib-content a {
  color: var(--accent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  transition: border-color 0.15s;
}
.lib-content a:hover { border-bottom-color: var(--accent); }
.lib-content blockquote {
  margin: 20px 0; padding: 14px 20px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  background: var(--code-bg); color: var(--text-muted);
}
.lib-content code {
  font-family: ui-monospace, Menlo, monospace; font-size: 0.88em;
  padding: 2px 6px; border-radius: 6px; background: var(--code-bg); color: var(--accent-hover);
}
.lib-content pre {
  margin: 18px 0; padding: 16px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-3); overflow-x: auto;
}
.lib-content pre code { padding: 0; background: none; color: var(--text); }
.lib-content img { border-radius: var(--radius-sm); border: 1px solid var(--border); margin: 8px 0; }
.lib-content hr { border: 0; border-top: 1px solid var(--border); margin: 30px 0; }
.lib-content table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 14px; display: block; overflow-x: auto; }
.lib-content th, .lib-content td { padding: 10px 13px; border: 1px solid var(--border); text-align: left; }
.lib-content th { background: var(--bg-3); font-weight: 900; font-family: 'Benzin', system-ui, sans-serif; }

/* --------------------------- якоря (TOC + меню) -------------------------- */

.lib-toc {
  padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card-bg); font-size: 12.5px;
  max-height: calc(100vh - 120px); overflow-y: auto;
}
.lib-toc-title {
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 10px;
}
.lib-toc ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.lib-toc a {
  display: block; padding: 5px 9px; border-radius: 7px; color: var(--text-muted);
  border-left: 2px solid transparent; transition: color 0.14s, border-color 0.14s;
}
.lib-toc a:hover { color: var(--text); }
.lib-toc a.is-active { color: var(--accent); border-left-color: var(--accent); }
.lib-toc .toc-h3 a { padding-left: 20px; font-size: 12px; }

.lib-anchor-menu { position: relative; margin: 0 0 18px; }
.lib-anchor-toggle {
  display: inline-flex; align-items: center; gap: 9px; padding: 9px 14px; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text-muted);
  font-family: inherit; font-size: 13px; cursor: pointer;
}
.lib-anchor-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.lib-anchor-panel {
  position: absolute; z-index: 60; top: calc(100% + 6px); left: 0; width: min(420px, 90vw);
  max-height: 50vh; overflow-y: auto; padding: 8px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow);
}
.lib-anchor-panel[hidden] { display: none; }
.lib-anchor-panel a { display: block; padding: 8px 11px; border-radius: var(--radius-xs); font-size: 13px; color: var(--text-muted); }
.lib-anchor-panel a:hover { background: var(--bg-3); color: var(--text); }
.lib-anchor-panel .lvl3 { padding-left: 24px; font-size: 12.5px; }

/* ------------------------------- пагинация ------------------------------- */

.lib-pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-top: 44px; padding-top: 22px; border-top: 1px solid var(--border);
}
.lib-pager-item {
  display: flex; flex-direction: column; gap: 4px; padding: 13px 15px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg);
  transition: border-color 0.16s, transform 0.16s;
}
.lib-pager-item:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.lib-pager-item.is-next { text-align: right; }
.lib-pager-dir { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); }
.lib-pager-title { font-size: 14px; }

/* ---------------------------- прогресс чтения ---------------------------- */

.lib-progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 100%;
  transform: scaleX(0); transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent-hover));
  z-index: 1200;
}

/* ------------------------- палитра поиска (Ctrl+K) ----------------------- */

.cmdk {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 11vh 18px 18px;
}
.cmdk[hidden] { display: none; }
.cmdk-backdrop {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}
.cmdk-box {
  position: relative; width: min(660px, 100%);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--bg-2); box-shadow: 0 40px 90px rgba(0, 0, 0, 0.65);
  overflow: hidden; animation: cmdkIn 0.28s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cmdkIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.cmdk-input-row { display: flex; align-items: center; gap: 12px; padding: 15px 17px; border-bottom: 1px solid var(--border); }
.cmdk-input-row svg { width: 17px; height: 17px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.cmdk-input-row input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font-family: inherit; font-size: 15px; }
.cmdk-results { max-height: 52vh; overflow-y: auto; padding: 8px; }
.cmdk-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 10px 13px; border-radius: var(--radius-xs); border-left: 2px solid transparent;
}
.cmdk-item.is-active { background: var(--bg-3); border-left-color: var(--accent); }
.cmdk-item-title { font-size: 14px; }
.cmdk-item-sec { font-size: 11px; color: var(--accent); }
.cmdk-item-desc {
  grid-column: 1 / -1; font-size: 12px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cmdk-empty { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.cmdk-foot { padding: 9px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }

/* ------------------------------- поиск ----------------------------------- */

.lib-search-form { display: flex; gap: 10px; margin-top: 14px; }
.lib-search-form input {
  flex: 1; padding: 12px 15px; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text);
  font-family: inherit; font-size: 15px; outline: none;
}
.lib-search-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.lib-search-count { margin: 6px 0 14px; }
.lib-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lib-results li { padding: 15px 17px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg); }
.lib-results li > a { font-size: 15.5px; color: var(--accent); }
.lib-results p { margin: 6px 0 0; }
.lib-snip { font-size: 13px; color: var(--text-muted); }
.lib-results-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }

/* ------------------------------- формы ----------------------------------- */

.lib-form { display: flex; flex-direction: column; gap: 20px; }
.lib-form-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 66px; z-index: 50; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-2) 90%, transparent); backdrop-filter: blur(12px);
}
.lib-form-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.lib-form-status { font-size: 12px; color: var(--text-muted); }
.lib-form-status.is-ok { color: var(--ok); }
.lib-form-status.is-error { color: var(--danger); }

.lib-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.lib-field { display: flex; flex-direction: column; gap: 7px; }
.lib-field.span2 { grid-column: 1 / -1; }
.lib-field > span { font-size: 11px; letter-spacing: 1.3px; text-transform: uppercase; color: var(--text-muted); }
.lib-field > span small { text-transform: none; letter-spacing: 0; opacity: 0.7; }
.lib-field input[type='text'], .lib-field input[type='number'], .lib-field select, .lib-field textarea {
  padding: 10px 12px; border-radius: var(--radius-xs); border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text); font-family: inherit; font-size: 14px; outline: none; width: 100%;
}
.lib-field input:focus, .lib-field select:focus { border-color: var(--accent); }
.lib-field input[readonly] { opacity: 0.65; }
.lib-field > small { font-size: 11.5px; color: var(--text-muted); }
.lib-field > small b { color: var(--accent); }

.lib-cover-row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.lib-cover-row input[type='text'] { flex: 1; min-width: 220px; }
.lib-cover-preview { margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius-xs); overflow: hidden; max-width: 360px; }
.lib-cover-preview img { display: block; width: 100%; max-height: 170px; object-fit: cover; }

/* ------------------------------- Quill ----------------------------------- */

.q-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 9px;
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--bg-3);
}
.q-toolbar .ql-formats { display: flex; align-items: center; gap: 3px; margin: 0 6px 0 0; }
.q-toolbar button, .q-toolbar select, .q-custom, .q-color {
  border: 1px solid var(--border) !important; border-radius: 7px !important; background: var(--bg-2) !important;
  color: var(--text) !important; cursor: pointer; height: 29px; min-width: 29px;
  display: inline-flex; align-items: center; justify-content: center; font-family: inherit; font-size: 12px;
}
.q-toolbar button svg { fill: currentColor; }
.q-toolbar button:hover, .q-custom:hover, .q-color:hover { border-color: var(--accent) !important; }
.q-toolbar .ql-active, .q-toolbar button.ql-active { border-color: var(--accent) !important; color: var(--accent) !important; }
.q-toolbar select { padding: 0 8px; }
.q-color { position: relative; overflow: hidden; width: 33px; }
.q-color input[type='color'] { position: absolute; inset: -6px; width: 200%; height: 200%; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.q-color-ico { font-size: 13px; font-weight: 900; pointer-events: none; }
.q-color-bg .q-color-ico {
  display: block; width: 14px; height: 14px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
}
.q-editor {
  min-height: 420px; border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm); background: var(--bg-3);
}
.ql-toolbar.ql-snow { border: 0; }
.ql-container.ql-snow { border: 0; font-family: inherit; font-size: 15px; }
.ql-editor { min-height: 420px; line-height: 1.7; color: var(--text); }
.ql-editor.ql-blank::before { color: var(--text-muted) !important; font-style: normal; }
.ql-snow .ql-stroke { stroke: var(--text); }
.ql-snow .ql-fill { fill: var(--text); }
.ql-snow .ql-picker { color: var(--text); }
.ql-snow .ql-picker-options { background: var(--bg-2); border-color: var(--border) !important; }
.ql-snow a { color: var(--accent); }
.ql-editor blockquote { border-left: 3px solid var(--accent); padding-left: 14px; color: var(--text-muted); }
.ql-editor pre.ql-syntax, .ql-editor pre { background: var(--bg-2); color: var(--text); border-radius: 10px; padding: 12px; }

/* ------------------------------ превью ----------------------------------- */

.lib-preview { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg); padding: 18px 20px; }
.lib-preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted);
}

/* ------------------------------- книги ----------------------------------- */

.lib-book-head { display: flex; gap: 22px; align-items: flex-start; margin-bottom: 24px; }
.lib-book-cover {
  flex-shrink: 0; width: 104px; height: 140px; display: grid; place-items: center; font-size: 38px;
  border-radius: 4px 10px 10px 4px; border: 1px solid var(--border-strong);
  background:
    linear-gradient(90deg, rgba(201,166,107,0.25) 0 6px, transparent 6px),
    linear-gradient(160deg, #2a2520, #16141a);
  box-shadow: 8px 12px 28px rgba(0,0,0,0.4);
  transition: transform 0.35s var(--ease);
}
.lib-book-cover:hover { transform: rotateY(-8deg) translateX(4px); }
.lib-book-head h1 { margin: 0 0 8px; font-size: clamp(23px, 3.2vw, 34px); }
.lib-chapters { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.lib-chapters a {
  display: flex; align-items: baseline; gap: 12px; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-xs); background: var(--card-bg);
  transition: border-color 0.15s, transform 0.2s var(--ease), box-shadow 0.2s;
}
.lib-chapters a:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  transform: translateX(6px);
  box-shadow: -4px 0 0 var(--accent);
}
.lib-ch-num {
  flex-shrink: 0; width: 25px; height: 25px; display: grid; place-items: center;
  border-radius: 7px; font-size: 11px; background: var(--bg-3); color: var(--accent);
  border: 1px solid var(--border);
}
.lib-ch-title { font-size: 14px; }
.lib-ch-desc { flex: 1; font-size: 12px; color: var(--text-muted); }

/* ------------------------------ ревизии ---------------------------------- */

.lib-revs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.lib-rev {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 15px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg);
}
.lib-rev-main b { display: block; font-size: 14px; margin-bottom: 3px; }

/* --------------------------- управление -------------------------------- */

.lib-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; align-items: start; }
.lib-manage-list { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lib-manage-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 15px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg);
}
.lib-manage-list b { display: block; font-size: 14px; }
.lib-manage-list .lib-muted { font-size: 11.5px; }
.lib-manage-actions { display: flex; gap: 7px; flex-shrink: 0; }

@media (max-width: 1000px) {
  .lib-grid-2 { grid-template-columns: 1fr; }
}

/* --------------------------- пустые состояния ---------------------------- */

.lib-empty { text-align: center; padding: 64px 20px; max-width: 560px; margin: 0 auto; }
.lib-empty-ico { font-size: 44px; margin-bottom: 12px; opacity: 0.85; }
.lib-empty h1 { margin: 0 0 12px; font-size: 28px; }
.lib-empty-actions { display: flex; gap: 11px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

/* ------------------------------- футер ----------------------------------- */

.lib-footer { border-top: 1px solid var(--border); margin-top: 48px; }
.lib-footer-inner {
  display: grid; grid-template-columns: 1.4fr 1fr 1.2fr; gap: 26px;
  padding: 32px 40px; font-size: 13px;
}
.lib-footer-brand { font-weight: 900; letter-spacing: 1.4px; margin-bottom: 8px; }
.lib-footer-brand span { color: var(--accent); }
.lib-footer-links { display: flex; flex-direction: column; gap: 7px; }
.lib-footer-links a { color: var(--text-muted); transition: color 0.15s; }
.lib-footer-links a:hover { color: var(--accent); }
.lib-footer-copy { color: var(--text-muted); font-size: 12px; }
.lib-who { display: block; margin-top: 8px; color: var(--accent); font-size: 11px; }

/* ----------------------------- адаптивность ------------------------------ */

@media (max-width: 1080px) {
  :root { --side-w: 228px; }
  .lib-main { padding: 22px 24px 70px; }
  .lib-footer-inner { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .lib-burger { display: flex; }
  .lib-topnav { display: none; }
  .lib-shell { grid-template-columns: minmax(0, 1fr); }
  .lib-side {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(310px, 86vw); height: auto; z-index: 1000;
    padding: 16px; background: var(--bg-2); border-right: 1px solid var(--border);
    transform: translateX(-104%); transition: transform 0.28s var(--ease); overflow-y: auto;
  }
  .lib-side.is-open { transform: translateX(0); box-shadow: 0 0 80px rgba(0, 0, 0, 0.6); }
  .lib-search-trigger span { display: none; }
  .lib-form-grid { grid-template-columns: 1fr; }
  .lib-pager { grid-template-columns: 1fr; }
  .lib-footer-inner { grid-template-columns: 1fr; padding: 26px 20px; }
  .lib-main { padding: 20px 16px 70px; }
  .lib-card:hover { transform: translateY(-4px); }
}

@media (max-width: 560px) {
  .lib-hero h1 { font-size: 28px; }
  .lib-book-head { flex-direction: column; gap: 16px; }
  .lib-user { display: none; }
  .lib-card-cover { height: 108px; }
  .lib-card.has-cover::before { top: 108px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
  .lib-boot { display: none !important; }
  body.lib.is-booting > :not(.lib-boot) { visibility: visible !important; }
}
