/* Дополнение к styles.css (#4070): подключается после него, поэтому равные по весу правила здесь главнее. */

/* ——— Единая типографика читалки: «По-русски», «Рядом» и «Оригинал» — один шрифт, кегль, интерлиньяж и переносы ———
   Раньше «Рядом» уменьшал кегль до 17px, а колонка оригинала шла 16px с другим интерлиньяжем и цветом; переносы были
   только в русском режиме. Теперь размер задаёт одна переменная: статья — 18px (телефон 17px), книжная читалка — 19px
   (17px), во всех трёх режимах одинаково. */
:root { --read-fs: 18px; --read-lh: 1.72; }
@media (max-width: 760px) { :root { --read-fs: 17px; } }
.rd-pane { --read-fs: 19px; }
@media (max-width: 860px) { .rd-pane { --read-fs: 17px; } }
.lib-text, .lib-mode-both .lib-text,
.rd-pane .sheet-text, .rd-pane .lib-sheet .sheet-text, .rd-lib.lib-mode-both .lib-sheet .sheet-text {
  font-size: var(--read-fs);
  line-height: var(--read-lh);
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
  font-optical-sizing: auto;
}
/* Колонка оригинала «Рядом» — тот же кегль, интерлиньяж и цвет, что у перевода */
.lb-src { font-size: inherit; line-height: inherit; color: inherit; }
/* «Рядом»: колонки шире, чтобы строка каждой была той же длины, что у одной колонки (около 66 знаков) */
.rd-pane:has(.rd-lib.lib-mode-both) { max-width: 1440px; }
/* Переносы — у русского текста в любом режиме; у оригинала — только если язык издания известен (иначе перенос
   по чужим правилам: немецкий текст с пометкой «en» ломался бы по-английски) */
.lib-text :is(p, li):lang(ru), .lib-src-known .lib-text :is(p, li) { hyphens: auto; -webkit-hyphens: auto; }
/* Индексы не раздвигают строки: интерлиньяж ровный и у абзаца с x², CO₂ и сносками */
.lib-text sup, .lib-text sub { line-height: 0; }

/* ——— Листание «По страницам» (#4070): под листом колонцифра — номер страницы крупно, как в книге, и рядом «Назад» /
   «Дальше». Номер — кнопка списка страниц. Цели нажатия не меньше 44px, панель стоит под текстом и его не закрывает. */
.rd-pane .lib-sheet { scroll-margin-top: calc(var(--lib-controls-h, 54px) + 20px); }
.folio-nav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding: 12px 0 max(12px, env(safe-area-inset-bottom)); }
.fn-step { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--paper); font-weight: 500; color: var(--text); }
.fn-prev { justify-self: start; }
.fn-next { justify-self: end; }
a.fn-step:hover { border-color: var(--accent-line); color: var(--accent-dark); }
.fn-step[aria-disabled] { border-color: transparent; background: transparent; color: #a9b6af; }
.fn-here { display: inline-grid; grid-template-columns: auto auto auto; align-items: baseline; justify-content: center; column-gap: 6px; min-height: 48px; padding: 4px 14px; border: 0; border-radius: 12px; background: transparent; color: var(--text); }
.fn-here:hover { background: var(--accent-light); }
.fn-num { font-family: var(--read); font-size: 28px; line-height: 1; font-variant-numeric: oldstyle-nums proportional-nums; }
.fn-of { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fn-here svg { align-self: center; color: var(--muted); }
.fn-print { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
@media (max-width: 440px) {
  /* Узкий телефон: «Назад» и «Дальше» — квадратные кнопки со стрелкой, слово остаётся для экранного диктора */
  .fn-step { width: 48px; padding: 0; justify-content: center; }
  .fn-step span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* Список страниц: окно по центру, на телефоне — шторка снизу с отступом под системную полосу */
.pages-sheet { width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 720px); margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--paper); color: var(--text); box-shadow: 0 24px 60px #1b2b2329; overflow: auto; overscroll-behavior: contain; }
.pages-sheet::backdrop { background: #1b2b2347; }
.ps-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 8px 20px; background: var(--paper); }
.ps-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.ps-close { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.ps-close:hover { background: var(--page-bg); color: var(--text); }
.ps-go { padding: 4px 20px 14px; }
.ps-go label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.ps-go-row { display: flex; gap: 8px; }
.ps-go input { flex: 1; min-width: 0; height: 48px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--paper); font: inherit; font-size: 18px; color: var(--text); font-variant-numeric: tabular-nums; }
.ps-go input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.ps-go .btn { min-height: 48px; }
.ps-hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.ps-ranges { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 10px; }
.ps-range { display: inline-flex; align-items: center; gap: 5px; min-height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--text); }
a.ps-range:hover { border-color: var(--accent-line); color: var(--accent-dark); }
.ps-range[aria-current] { border-color: var(--accent); background: var(--accent-light); color: var(--accent-dark); }
.ps-range.is-shut { border-style: dashed; color: #8f9c95; }
.ps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; padding: 0 20px 14px; }
.ps-grid a { display: grid; place-items: center; height: 44px; border-radius: 10px; background: var(--page-bg); font-weight: 500; font-variant-numeric: tabular-nums; }
.ps-grid a:hover { background: var(--accent-light); color: var(--accent-dark); }
.ps-grid a[aria-current] { background: var(--accent-dark); color: #fff; }
.ps-shut { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 20px 14px; padding: 10px 12px; border-radius: 10px; background: var(--page-bg); font-size: 14px; line-height: 1.45; color: #5d6d65; }
.ps-shut a { color: var(--accent-dark); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.ps-sub { margin: 6px 20px 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
.ps-toc { margin: 0; padding: 0 20px 20px; list-style: none; }
.ps-toc li { border-top: 1px solid var(--border); }
.ps-toc a, .ps-toc li > span { display: block; padding: 11px 0; font-family: var(--read); font-size: 15.5px; line-height: 1.35; }
.ps-toc a:hover { color: var(--accent-dark); }
.ps-toc .is-shut { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #8f9c95; }
@media (max-width: 560px) {
  .pages-sheet { width: 100%; max-width: none; max-height: 86vh; margin: auto 0 0; border-bottom: 0; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
@media (prefers-reduced-motion: no-preference) {
  .pages-sheet:popover-open { animation: ps-in 0.18s ease-out; }
  @keyframes ps-in { from { opacity: 0; transform: translateY(12px); } }
}
/* Номер под листом показывает листалка (с номером «как в книге», если он другой) — колонтитул листа не повторяет его */
.rd-lib:has(.folio-nav) .lib-sheet .folio { display: none; }

/* ——— Устройства и чтение (#4070): профиль, выбор устройства для замены при входе, страница «читать сейчас нельзя» ——— */
.btn-quiet { border: 1px solid var(--border); background: var(--paper); color: var(--text); box-shadow: none; }
.btn-quiet:hover { border-color: var(--accent-line); background: var(--paper); color: var(--accent-dark); }
.acc { max-width: 760px; margin: 0 auto 64px; }
.acc-intro p { max-width: 62ch; }
.acc-notice { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--accent-light); color: var(--accent-dark); }
.acc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0 0 16px; }
.acc-stat { padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--paper); }
.acc-stat b { display: block; font-family: var(--read); font-size: 30px; font-weight: 600; line-height: 1.1; font-variant-numeric: oldstyle-nums proportional-nums; }
.acc-stat b span { font-family: var(--ui); font-size: 15px; font-weight: 500; color: var(--muted); }
.acc-stat small { display: block; margin-top: 4px; font-size: 13.5px; color: var(--muted); }
.acc-card { margin-bottom: 16px; }
.acc-card h2 { margin: 0 0 12px; font-size: 19px; font-weight: 600; }
.acc-devs, .acc-live-list { margin: 0; padding: 0; list-style: none; }
.acc-dev, .acc-live-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px 14px; padding: 14px 0; border-top: 1px solid var(--border); }
.acc-dev:first-child, .acc-live-list li:first-child { border-top: 0; }
.dev-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--page-bg); color: var(--muted); }
.acc-dev.is-here .dev-ico { background: var(--accent-light); color: var(--accent-dark); }
.acc-dev-text b, .acc-live-list b { font-weight: 600; }
.acc-dev-text small, .acc-live-list small { display: block; margin-top: 2px; font-size: 13.5px; color: var(--muted); }
.acc-tag, .acc-reading { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 20px; font-size: 12.5px; font-weight: 500; vertical-align: 1px; }
.acc-tag { background: var(--accent-light); color: var(--accent-dark); }
.acc-reading { background: #fff4d6; color: #7a5b00; }
.acc-dev-acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.acc-dev-acts form, .acc-live-list form { margin: 0; }
.acc-note { margin: 12px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.acc-code { margin: 0 0 8px; }
.acc-code code { display: inline-block; padding: 6px 12px; border-radius: 10px; background: var(--page-bg); font-family: var(--ui); font-size: 22px; font-weight: 600; letter-spacing: 1.5px; font-variant-numeric: tabular-nums; }
.acc-mark p, .acc-policy p { max-width: 64ch; line-height: 1.6; }
.acc-limit { max-width: 640px; margin: 32px auto 64px; }
.acc-limit h1 { margin: 0 0 10px; font-size: 24px; line-height: 1.3; }
.acc-limit > p { line-height: 1.6; color: #3c4a43; }
.acc-limit-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 18px; }
.reading-stop { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; background: #fff4d6; color: #5c4500; line-height: 1.5; }
.reading-stop a { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; }
/* Выбор устройства в форме входа */
.dev-pick { margin: 0 0 4px; padding: 0; border: 0; }
.dev-pick legend { margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.dev-opt { display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: center; gap: 10px; min-height: 52px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.dev-opt + .dev-opt { margin-top: 6px; }
.dev-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-light); }
.dev-opt input { margin: 0; accent-color: var(--accent-dark); }
.dev-opt .dev-ico { width: 34px; height: 34px; }
.dev-opt small { display: block; font-size: 12.5px; color: var(--muted); }
.dev-pick-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
@media (max-width: 560px) {
  .acc-stats { grid-template-columns: minmax(0, 1fr); }
  .acc-stat { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .acc-dev { grid-template-columns: auto minmax(0, 1fr); }
  .acc-dev-acts { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ——— Платное открытое читателю (#4070, protect/): маркировка кодом аккаунта, рисунки не перетаскиваются, печать без
   текста книги. Знак — фон (--wm, decorate.js): экранный диктор, поиск по странице и выделение его не видят. */
[data-protect] .lib-text { background-image: var(--wm); background-size: 280px 180px; }
[data-protect] .lib-fig { position: relative; }
[data-protect] .lib-fig::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background-image: var(--wm); background-size: 200px 130px; pointer-events: none; }
[data-protect] img { -webkit-user-drag: none; -webkit-touch-callout: none; }
.protect-note { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 60; width: min(560px, calc(100vw - 32px)); transform: translateX(-50%); padding: 12px 16px; border-radius: 12px; background: #26342e; color: #fff; font-size: 14.5px; line-height: 1.45; box-shadow: 0 12px 30px #1b2b2340; }
.protect-note[hidden] { display: none; }
@media print {
  [data-protect] .sheet-text, [data-protect] .lib-text, [data-protect] .lib-figs, [data-protect] .folio-nav, [data-protect] .pages-sheet { display: none !important; }
  [data-protect]::before { content: 'Печать платных книг Awamed отключена. Читать книгу — на сайте awamed.ru.'; display: block; padding: 24px 0; font-size: 16px; }
}

/* Cipher glyphs have no native word boundaries; select each displayed word as a unit. */
/* Слово целиком по двойному щелчку — только у мыши. На iPhone/iPad user-select: all ломает долгое нажатие: выделение
   начиналось от начала страницы, а не от пальца (#4834). Для заметок на сенсорном экране touch-selection.js выбирает слова по координатам. */
@media (hover: hover) and (pointer: fine) {
  [data-cipher] .cipher-word { -webkit-user-select: all; user-select: all; }
}

/* После инициализации показываем свои маркеры заметок и на открытых страницах
   читалки: системное меню Safari перекрывает кнопку сохранения. */
@media (hover: none) {
  html.frag-touch main [data-protect][data-cipher],
  html.frag-touch main.rd-pane .lib-text { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
.frag-selection { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.frag-selection i { position: absolute; background: #2785df33; pointer-events: none; }
.frag-handle { position: fixed; z-index: 35; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.frag-handle[hidden] { display: none; }
.frag-handle::before { content: ''; position: absolute; left: 21px; top: 22px; width: 2px; height: calc(var(--line) + 22px); background: #147be0; }
.frag-handle::after { content: ''; position: absolute; left: 16px; top: 16px; width: 12px; height: 12px; border-radius: 50%; background: #147be0; }
.frag-handle-1::before { top: calc(-1 * var(--line)); }
.frag-handle:focus-visible { outline: 2px solid #147be0; border-radius: 8px; }

/* Keep page submission reachable on touch keyboards. */
.rd-pane .pg-go { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; max-width: 100%; }
.rd-pane .pg-go label { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.rd-pane .pg-go input { min-width: 0; max-width: 72px; font-size: 16px; }
.rd-pane .pg-go button { position: static; width: auto; min-height: 40px; height: auto; clip: auto; overflow: visible; padding: 8px 12px; border: 1px solid #dce6e1; border-radius: 10px; background: #fff; color: #245849; font: inherit; font-size: 14px; font-weight: 600; -webkit-appearance: none; appearance: none; cursor: pointer; }
.rd-pane .pg-go button:active { background: #e8f4ee; }
.rd-pane .pager { flex-wrap: wrap; gap: 8px; }
.rd-pane .pager .pg-mid { min-width: 0; }
@media (max-width: 480px) {
  .rd-pane .pager .pg-mid { flex: 1 0 100%; order: -1; }
}
