:root {
  --accent: #6366f1;
  --ink: #18181b;
  --ink-soft: #52525b;
  --ink-faint: #a1a1aa;
  --line: #e8e8ec;
  --bg-soft: #f7f7f8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.07);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #fff;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }

/* ---------- Кнопки ---------- */
.btn {
  font: inherit; font-size: 15.5px; font-weight: 500;
  padding: 10px 18px; border-radius: 99px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  cursor: pointer; transition: all .15s; text-decoration: none;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { border-color: #d4d4d8; background: var(--bg-soft); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; color: var(--ink-faint); }
.btn.ghost:hover { background: var(--bg-soft); color: var(--ink-soft); }
.btn.small { font-size: 14px; padding: 7px 14px; }
.spacer { flex: 1; }

/* ---------- Общая шапка ---------- */
.appbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(255,255,255,.88); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.back {
  text-decoration: none; color: var(--ink-soft); font-size: 21px; line-height: 1;
  padding: 6px 11px; border-radius: 9px;
}
.back:hover { background: var(--bg-soft); }
.me { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 4px 10px 4px 4px; border-radius: 99px; }
.me:hover { background: var(--bg-soft); }
.me-name { font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.streak { font-size: 15px; font-weight: 600; color: var(--ink-soft); padding: 0 6px; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; flex: none;
}
.avatar.xl { width: 96px; height: 96px; font-size: 40px; }

/* ---------- Полка ---------- */
.shelf-page { max-width: 940px; margin: 0 auto; padding: 34px 22px 80px; }
.shelf-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.shelf-head h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.today { color: var(--ink-soft); font-size: 15px; margin: 0 0 22px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 26px 22px; margin-top: 20px; }
.shelf-card { text-decoration: none; color: inherit; display: block; }
.cover {
  display: grid; place-items: center; position: relative;
  aspect-ratio: 2/3; border-radius: 10px; padding: 16px;
  background: var(--c); background-size: cover; background-position: center;
  box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s;
}
.shelf-card:hover .cover { transform: translateY(-4px); box-shadow: 0 10px 28px rgba(0,0,0,.16); }
.cover-title { color: #fff; font-weight: 750; font-size: 19px; line-height: 1.25; text-align: center; letter-spacing: -.01em; }
.cover-flag {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  font-size: 11px; background: rgba(255,255,255,.92); color: #333; padding: 3px 9px; border-radius: 99px; white-space: nowrap;
}
.card-del {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.92); color: #52525b; font-size: 14px; line-height: 1;
  cursor: pointer; opacity: 0; transition: opacity .15s, background .15s;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.shelf-card:hover .card-del { opacity: 1; }
.card-del:hover { background: #fff; color: #dc2626; }
/* на планшете и телефоне наведения нет — кнопка видна всегда */
@media (hover: none) { .card-del { opacity: .92; } }
@media (max-width: 1000px) { .card-del { opacity: .92; } }

.shelf-title { display: block; margin-top: 11px; font-weight: 600; font-size: 15.5px; }
.shelf-meta { display: block; color: var(--ink-faint); font-size: 13px; margin-top: 2px; }
.untitled { color: var(--ink-faint); font-weight: 400; }
.empty { color: var(--ink-soft); line-height: 1.6; }

/* ---------- Настройки ---------- */
.me-page { max-width: 520px; margin: 0 auto; padding: 34px 22px 80px; }
.me-page h1 { font-size: 27px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 24px; }
.me-avatar-row { display: flex; justify-content: center; margin-bottom: 26px; }
.avatar-drop { display: grid; justify-items: center; gap: 10px; cursor: pointer; }
.avatar-hint { color: var(--ink-faint); font-size: 13.5px; }
.field { display: block; margin-bottom: 20px; }
.field > span { display: block; font-size: 14px; color: var(--ink-soft); margin-bottom: 7px; }
.field input {
  font: inherit; font-size: 17px; width: 100%; padding: 12px 15px;
  border: 1px solid var(--line); border-radius: var(--radius); outline: 0;
}
.field input:focus { border-color: var(--accent); }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--ink); }
.me-actions { display: flex; align-items: center; gap: 14px; margin-top: 28px; }

/* ---------- Список (корзина) ---------- */
.list-page { max-width: 720px; margin: 0 auto; padding: 34px 22px 80px; }
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.list-head h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 16px; margin: 0 -16px; border-radius: var(--radius);
}
.item:hover { background: var(--bg-soft); }
.item + .item { border-top: 1px solid var(--line); }
.item-title { font-size: 16.5px; font-weight: 600; flex: 1; }
.item-meta { display: flex; align-items: center; gap: 12px; color: var(--ink-faint); font-size: 13px; }

/* ---------- Вход ---------- */
.login { max-width: 320px; margin: 26vh auto 0; padding: 0 20px; display: flex; flex-direction: column; gap: 12px; }
.login::before { content: '📖'; font-size: 44px; text-align: center; }
.login input, .login button {
  font: inherit; font-size: 16px; padding: 13px 16px; border-radius: var(--radius); outline: 0;
  border: 1px solid var(--line);
}
.login button { border: 0; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }

/* ---------- Рабочее место: главы + редактор ---------- */
.editor-body { background: #fff; }
.book-title {
  font: inherit; font-size: 17px; font-weight: 700; letter-spacing: -.01em;
  border: 0; outline: 0; background: transparent; padding: 6px 8px; border-radius: 8px;
  min-width: 120px; max-width: 340px; flex: 1;
}
.book-title:hover, .book-title:focus { background: var(--bg-soft); }
.book-title::placeholder { color: var(--ink-faint); font-weight: 500; }

.workspace { display: flex; align-items: flex-start; }
.chapters {
  position: sticky; top: 56px; flex: none; width: 240px;
  height: calc(100vh - 56px); overflow-y: auto;
  border-right: 1px solid var(--line); padding: 16px 12px 100px; background: var(--bg-soft);
}
.chapters-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-faint); padding: 0 8px 10px;
}
.close-chapters { display: none; font-size: 15px; padding: 4px 8px; }
.chapters-backdrop { display: none; }
.chapter-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px;
  cursor: pointer; font-size: 14.5px; color: var(--ink-soft);
}
.chapter-item:hover { background: #ececf0; }
.chapter-item.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.chapter-n { width: 20px; color: var(--ink-faint); font-size: 12.5px; flex: none; text-align: center; }
.chapter-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-w { color: var(--ink-faint); font-size: 12px; flex: none; }
.chapter-tools { display: none; gap: 1px; flex: none; }
.chapter-item:hover .chapter-tools, .chapter-item.on .chapter-tools { display: flex; }
.chapter-item:hover .chapter-w, .chapter-item.on .chapter-w { display: none; }
.mini {
  border: 0; background: none; color: var(--ink-faint); cursor: pointer;
  font-size: 13px; padding: 3px 5px; border-radius: 6px; line-height: 1;
}
.mini:hover { background: #fff; color: var(--ink); }
.mini.del:hover { background: #fef2f2; color: #dc2626; }
.add-chapter { width: 100%; margin-top: 12px; justify-content: center; font-size: 14px; }
.chapters-toggle { display: none; }

.chapter-main { flex: 1; min-width: 0; }
.editor-wrap { max-width: 720px; margin: 0 auto; padding: 40px 26px 40vh; }
.title {
  width: 100%; border: 0; outline: 0; resize: none; overflow: hidden;
  font: inherit; font-size: 34px; font-weight: 800; line-height: 1.2; letter-spacing: -.02em;
  padding: 0 0 8px; background: transparent;
}
.title::placeholder { color: #d4d4d8; }

.codex-editor__redactor { padding-bottom: 120px !important; }
.ce-block__content, .ce-toolbar__content { max-width: 660px; }
.ce-paragraph, .cdx-block { font-size: 18.5px; line-height: 1.7; }
h2.ce-header { font-size: 25px; letter-spacing: -.015em; }
h3.ce-header { font-size: 20px; }
.image-tool__image-picture { border-radius: var(--radius); }

/* ---------- Нижняя панель с отменой ---------- */
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.bottombar-inner { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bottombar-inner > * { flex: none; }
.bottombar-inner > .spacer { flex: 1; }
.counter { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* На планшете в вертикальном положении всё в строку не встаёт. Прячем подписи только у стрелок
   отмены — они и так понятны, — а у «Проверить» и «Причесать» подписи оставляем: без них ребёнку
   не догадаться, что делают эти кнопки. */
@media (max-width: 1000px) {
  .bottombar .btn.undo .label { display: none; }
  .bottombar .btn.undo { padding: 11px 15px; gap: 0; }
  .bottombar .counter { display: none; }
  .bottombar .save-status { min-width: 0; font-size: 13px; }
  .bottombar-inner { gap: 8px; }
}

/* На телефоне и это не помещается — переносим в две строки, ничего не пряча */
@media (max-width: 620px) {
  .bottombar-inner { flex-wrap: wrap; justify-content: center; row-gap: 8px; }
  .bottombar-inner > .spacer { display: none; }
  /* верхняя панель тоже: первой строкой название книги, второй — кнопки */
  .editor-body .appbar { flex-wrap: wrap; row-gap: 8px; }
  .editor-body .appbar .book-title { max-width: none; }
  .editor-body .appbar .spacer { flex-basis: 100%; height: 0; }
}
.btn.undo { font-size: 15px; padding: 11px 20px; font-weight: 600; }
.btn.undo.flash { background: var(--accent); border-color: var(--accent); color: #fff; }
.counter { color: var(--ink-soft); font-size: 14px; }
.save-status { color: var(--ink-faint); font-size: 13.5px; min-width: 92px; text-align: right; }

/* ---------- Кнопки-иконки: экспорт главы (сверху) и скачивание книги (снизу) ---------- */
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  color: var(--ink-soft); cursor: pointer; transition: all .15s;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); border-color: #d4d4d8; }
.icon-btn:active { transform: scale(.94); }

.btn.tidy { gap: 8px; padding: 9px 16px 9px 13px; }
.btn.tidy svg { width: 19px; height: 19px; color: var(--accent); }
.btn.tidy:disabled { opacity: .5; cursor: default; }

.popmenu {
  position: fixed; z-index: 250; min-width: 210px; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 34px rgba(0,0,0,.16);
}
.popmenu-head {
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-faint); padding: 7px 10px 8px;
}
.popmenu a {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 9px 10px; border-radius: 9px; text-decoration: none; color: var(--ink); font-size: 14.5px;
}
.popmenu a:hover { background: var(--bg-soft); }
.popmenu-ext { color: var(--ink-faint); font-size: 12.5px; }

/* ---------- Офлайн ---------- */
.net-state {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; font-weight: 600; color: #b45309;
  background: #fef3c7; padding: 5px 11px; border-radius: 99px; white-space: nowrap;
}
.net-state svg { width: 16px; height: 16px; }
/* без сервера эти кнопки бессмысленны — гасим, но не прячем, чтобы было понятно, что они есть */
body.offline .needs-net { opacity: .38; pointer-events: none; filter: grayscale(1); }

.offline-page { max-width: 460px; margin: 16vh auto 0; padding: 0 24px; text-align: center; }
.offline-page img { border-radius: 22px; margin-bottom: 22px; }
.offline-page h1 { font-size: 27px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 12px; }
.offline-page p { color: var(--ink-soft); font-size: 16.5px; line-height: 1.6; margin: 0 0 24px; }

/* ---------- Модалки ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 200; background: rgba(24,24,27,.42);
  display: grid; place-items: center; padding: 20px;
}
/* display:grid у класса сильнее атрибута hidden — возвращаем hidden силу, иначе подложка всегда поверх страницы */
.modal-back[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 26px; width: min(560px, 100%); max-height: 84vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.modal-hint { color: var(--ink-soft); font-size: 14.5px; line-height: 1.5; margin: 0 0 18px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 22px; }
.cover-preview {
  aspect-ratio: 2/3; width: 150px; margin: 16px auto; border-radius: 10px; padding: 14px;
  background: var(--c); background-size: cover; background-position: center;
  display: grid; place-items: center; color: #fff; font-weight: 750; text-align: center; box-shadow: var(--shadow);
}
/* Список замечаний проверки */
.issues { display: grid; gap: 10px; max-height: 52vh; overflow-y: auto; }
.issue { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; }
.issue.done { opacity: .55; }
.issue-top { display: flex; align-items: baseline; gap: 10px; }
.issue-frag { font-weight: 650; font-size: 16px; }
.issue-kind { color: var(--ink-faint); font-size: 12.5px; }
.issue-msg { color: var(--ink-soft); font-size: 14px; line-height: 1.45; margin: 5px 0 9px; }
.issue-fixes { display: flex; flex-wrap: wrap; gap: 7px; }
.issue-fixes .btn { font-size: 14px; padding: 6px 13px; }
.issue-nofix, .issue-done { color: var(--ink-faint); font-size: 13.5px; }

.vers { display: grid; gap: 2px; }
.ver { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; font-size: 14px; }
.ver:hover { background: var(--bg-soft); }
.ver-date { flex: 1; }
.ver-w, .ver-tag { color: var(--ink-faint); font-size: 13px; }
.ver-preview {
  background: var(--bg-soft); border-radius: 12px; padding: 16px; max-height: 46vh; overflow: auto;
  white-space: pre-wrap; font: inherit; font-size: 15px; line-height: 1.6; color: var(--ink-soft);
}

/* ---------- Тосты ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 300; display: grid; gap: 8px; width: max-content; max-width: 92vw; }
.toast {
  display: flex; align-items: center; gap: 14px;
  background: #18181b; color: #fff; padding: 12px 18px; border-radius: 99px;
  font-size: 14.5px; box-shadow: 0 8px 30px rgba(0,0,0,.28);
}
.toast-btn { border: 0; background: none; color: #a5b4fc; font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
.toast-close { border: 0; background: none; color: #71717a; font: inherit; font-size: 13px; cursor: pointer; padding: 0 0 0 4px; }
.toast-close:hover { color: #fff; }

/* ---------- Читалка ---------- */
.reader { max-width: 680px; margin: 0 auto; padding: 56px 24px 90px; }
.reader h1 { font-size: 36px; font-weight: 800; line-height: 1.15; letter-spacing: -.025em; margin: 0 0 8px; }
.reader p, .reader li { font-size: 19.5px; line-height: 1.75; color: #27272a; }
/* Книжный вид: абзацы вплотную, первая строка с красной строки, переносы как в типографии */
.reader p { margin: 0; text-indent: 1.3em; hyphens: auto; -webkit-hyphens: auto; text-wrap: pretty; }
/* Первый абзац главы и абзац после заголовка, картинки, цитаты или звёздочек — без отступа */
.reader > p:first-of-type,
.reader h1 + p, .reader h2 + p, .reader h3 + p,
.reader figure + p, .reader blockquote + p, .reader hr + p, .reader ul + p, .reader ol + p { text-indent: 0; }
.reader h2 { font-size: 27px; margin: 40px 0 12px; letter-spacing: -.02em; }
.reader h3 { font-size: 21px; margin: 30px 0 10px; }
.reader ul, .reader ol { padding-left: 26px; }
.reader ul.checklist { list-style: none; padding-left: 4px; }
.reader figure { margin: 30px 0; }
.reader img { max-width: 100%; height: auto; display: block; border-radius: var(--radius); box-shadow: var(--shadow); }
.reader figcaption { color: var(--ink-faint); font-size: 14px; margin-top: 9px; text-align: center; }
.reader blockquote { margin: 30px 0; padding-left: 20px; border-left: 3px solid currentColor; }
.reader blockquote p { font-size: 21px; margin: 0; }
.reader blockquote cite { display: block; color: var(--ink-faint); font-size: 15px; font-style: normal; margin-top: 8px; }
.reader hr { border: 0; text-align: center; margin: 42px 0; }
.reader hr::before { content: '· · ·'; letter-spacing: .8em; color: var(--ink-faint); }
.reader-crumb { color: var(--ink-faint); font-size: 14px; margin-bottom: 26px; }
.reader-meta { color: var(--ink-faint); font-size: 15px; margin-bottom: 30px; }
.reader-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 56px; padding-top: 26px; border-top: 1px solid var(--line); }
.the-end { color: var(--ink-faint); font-size: 15px; }
.reader-actions { display: flex; gap: 12px; margin-top: 30px; }

.toc-page { text-align: center; }
.toc-page h1 { margin-top: 26px; }
.bookcover {
  width: 190px; aspect-ratio: 2/3; margin: 0 auto; border-radius: 12px; padding: 20px;
  background: var(--c); background-size: cover; background-position: center;
  display: grid; place-items: center; align-content: center; gap: 12px; box-shadow: var(--shadow);
}
.bookcover-title { color: #fff; font-weight: 750; font-size: 22px; line-height: 1.2; }
.bookcover-author { color: rgba(255,255,255,.85); font-size: 14px; }
.toc { text-align: left; margin-top: 30px; }
.toc-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 12px; margin: 0 -12px;
  border-radius: 12px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line);
}
.toc-item:hover { background: var(--bg-soft); }
.toc-n { color: var(--ink-faint); font-size: 14px; width: 22px; }
.toc-title { flex: 1; font-size: 17px; font-weight: 600; }
.toc-w { color: var(--ink-faint); font-size: 13px; }

/* ---------- Печать ---------- */
.print { max-width: 680px; margin: 0 auto; padding: 40px 24px 90px; }
.print-title { text-align: center; margin-bottom: 60px; }
.print-title h1 { font-size: 40px; font-weight: 800; margin: 0 0 10px; letter-spacing: -.025em; }
.print-author { color: var(--ink-soft); font-size: 17px; }
.print-chapter { margin-bottom: 50px; }
.print-chapter h2 { font-size: 26px; margin: 0 0 16px; }
.print p, .print li { font-size: 17px; line-height: 1.7; }
.print p { margin: 0; text-indent: 1.3em; hyphens: auto; -webkit-hyphens: auto; }
.print-chapter h2 + p, .print blockquote + p, .print figure + p, .print hr + p { text-indent: 0; }
.print img { max-width: 100%; height: auto; border-radius: 8px; }
.print-hint {
  position: fixed; bottom: 0; left: 0; right: 0; padding: 14px;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: rgba(255,255,255,.94); border-top: 1px solid var(--line); font-size: 14.5px; color: var(--ink-soft);
}
/* Настоящий книжный формат: страница A5 с полями, как в изданной книге.
   Внутреннее поле шире внешнего — под будущий корешок, если книгу сшивать. */
@page { size: A5 portrait; margin: 17mm 15mm 20mm 19mm; }

@media print {
  html, body { background: #fff !important; color: #000; }
  .no-print { display: none !important; }

  .print { max-width: none; margin: 0; padding: 0; }
  .print p, .print li {
    font-size: 11.5pt; line-height: 1.55; color: #000;
    orphans: 2; widows: 2;                 /* не оставлять одиночную строку абзаца на странице */
  }
  .print p { margin: 0; text-indent: 5.5mm; }
  .print-chapter h2 + p, .print blockquote + p, .print figure + p, .print hr + p { text-indent: 0; }

  /* Титульная страница — отдельным листом */
  .print-title { break-after: page; margin: 0; padding-top: 45mm; text-align: center; }
  .print-title h1 { font-size: 26pt; line-height: 1.15; margin: 0 0 6mm; }
  .print-author { font-size: 13pt; color: #333; }

  /* Каждая глава — с новой страницы, заголовок не отрывается от текста */
  .print-chapter { break-before: page; margin: 0; }
  .print-chapter .chapter-head { font-size: 16pt; margin: 0 0 7mm; break-after: avoid; page-break-after: avoid; }
  /* подзаголовки внутри главы — мельче и с воздухом сверху */
  .print-chapter h2:not(.chapter-head), .print-chapter h3 {
    font-size: 12.5pt; margin: 7mm 0 3mm; break-after: avoid; page-break-after: avoid;
  }
  .print-cover { display: block; width: 62mm; margin: 0 auto 9mm; border-radius: 2mm; }

  .print img { max-width: 100%; height: auto; break-inside: avoid; }
  .print blockquote { margin: 5mm 0; padding-left: 5mm; border-left: 2px solid #666; }
  .print hr { border: 0; text-align: center; margin: 7mm 0; }
  .print hr::before { content: '* * *'; letter-spacing: .5em; color: #666; }
}

/* ---------- Тёмная тема — только для публичных страниц ---------- */
@media (prefers-color-scheme: dark) {
  body.public { background: #101012; color: #e7e7ea; }
  body.public .reader p, body.public .reader li { color: #d0d0d6; }
  body.public .reader img { box-shadow: none; }
  body.public .reader-meta, body.public .reader-crumb, body.public .reader figcaption,
  body.public .reader hr::before, body.public .toc-n, body.public .toc-w, body.public .the-end { color: #6b6b74; }
  body.public .toc-item { border-bottom-color: #26262c; }
  body.public .toc-item:hover { background: #1b1b1f; }
  body.public .reader-nav { border-top-color: #26262c; }
  body.public .btn { background: #1b1b1f; border-color: #2a2a30; color: #e7e7ea; }
  body.public .btn:hover { background: #24242a; }
  body.public .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  body.public.print-body { background: #fff; color: var(--ink); }
}

/* ---------- Телефон и планшет ---------- */
@media (max-width: 820px) {
  .chapters {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 150; width: 250px;
    height: 100%; transform: translateX(-100%); transition: transform .2s;
    padding-top: calc(20px + env(safe-area-inset-top)); box-shadow: 0 0 40px rgba(0,0,0,.18);
  }
  .chapters.open { transform: none; }
  .close-chapters { display: block; }
  .chapters-backdrop { display: block; position: fixed; inset: 0; z-index: 140; background: rgba(24,24,27,.35); }
  .chapters-backdrop[hidden] { display: none; }
  .chapters-toggle { display: inline-flex; margin: 12px 0 -20px 20px; }
  .chapter-tools { display: flex !important; }
  .chapter-item .chapter-w { display: none; }
  .editor-wrap { padding: 22px 20px 45vh; }
  .title { font-size: 27px; }
  .book-title { font-size: 15.5px; }
  .reader h1 { font-size: 29px; }
  .reader p, .reader li { font-size: 18px; }
  .reader { padding: 34px 20px 70px; }
  .counter { display: none; }
  .me-name { display: none; }
}
