/* ==========================================================================
   Читалка — текст книги, корешок, выделения, всплывающие панели заметок.
   ========================================================================== */

.reader {
  position: relative;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 36px 0 120px;
  font-family: var(--font-read);
  font-size: var(--reader-size);
  line-height: var(--reader-lh);
  color: var(--ink);
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
  font-feature-settings: "kern" 1, "liga" 1;
}

.reader p { margin: 0 0 .85em; }
.reader p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------- титул книги ---- */
.bookhead { margin: 18px 0 0; text-align: left; hyphens: none; }
.bookhead__author {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: .015em;
  margin: 0 0 12px;
}
.bookhead__title {
  font-family: var(--font-read);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.14;
  letter-spacing: -.008em;
  margin: 0;
  color: var(--ink);
  text-align: left;
  hyphens: none;
}
.bookhead__sub {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
  margin: 14px 0 0;
  max-width: 46ch;
  text-align: left;
  hyphens: none;
}
.bookhead__orn { margin: 34px 0 0; color: var(--rule); }

.orn { display: block; }
.bookhead__orn .orn { margin-left: 0; }

/* ----------------------------------------------------- предупреждение --- */
.notice {
  position: relative;
  margin: 26px 0 6px;
  padding: 11px 38px 11px 13px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-2);
  text-align: left;
  hyphens: none;
}
.notice__x {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.notice__x:hover { background: var(--paper-2); color: var(--ink); }
.notice__x .ic { width: 14px; height: 14px; }

/* ------------------------------------------------- «продолжить чтение» -- */
.resume {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 24px 0 2px;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--paper-2);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-2);
  text-align: left;
  hyphens: none;
}
.resume__text { flex: 1 1 220px; min-width: 0; margin: 0; }
.resume__text b { font-weight: 500; color: var(--ink); }
.resume__acts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.resume .linkbtn { font-size: 12.5px; }

/* ------------------------------------------------------- главы/части ---- */
.chapter { position: relative; }
.chapter + .chapter { margin-top: 2.7em; }
.bookhead + .chapter { margin-top: 3.2em; }
.chapter--part + .chapter { margin-top: 2.4em; }

.chap-orn {
  display: flex;
  justify-content: center;
  color: var(--rule);
  margin: 0 0 2.3em;
}
.chap-orn .orn { width: 120px; height: 9px; }

.chapter__title {
  position: relative;
  font-family: var(--font-read);
  font-weight: 600;
  font-size: 27px;
  line-height: 1.21;
  letter-spacing: .004em;
  margin: 0 0 .92em;
  text-align: left;
  hyphens: none;
  color: var(--ink);
}
.chapter[data-level="2"] .chapter__title { font-size: 20px; line-height: 1.3; margin-bottom: .8em; }
.chapter[data-level="3"] .chapter__title {
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: .018em;
  margin-bottom: .75em;
}
.chapter[data-level="2"] { margin-top: 2.9em; }
.chapter[data-level="3"] { margin-top: 2.2em; }

.chapter__num {
  position: absolute;
  left: -56px;
  top: 5px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  color: var(--ink-3);
  line-height: 1;
}
.reader:not(.reader--margnums) .chapter__num { display: none; }

/* части книги — без абзацев: крупный разделитель, а не пустой блок */
.chapter--part { margin-top: 4em; text-align: center; }
.chapter--part:first-of-type { margin-top: 3em; }
.chapter--part .chap-orn { margin-bottom: 1.7em; }
.chapter--part .chapter__title {
  font-size: 30px;
  line-height: 1.2;
  text-align: center;
  letter-spacing: .006em;
  margin: 0;
  padding: 0 4%;
}

/* ------------------------------------------------------- конец книги ---- */
.book-end { margin: 4.2em 0 0; text-align: center; hyphens: none; }
.book-end .orn { color: var(--rule); margin: 0 auto; }
.book-end__meta {
  font-family: var(--font-ui);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 1.4em 0 0;
}

/* ------------------------------------------------------------ буквица --- */
.p--dropcap::first-letter {
  float: left;
  font-family: var(--font-read);
  font-weight: 600;
  font-size: 6.1em;
  line-height: .88;
  color: var(--accent);
  margin: .04em .06em 0 0;
}

/* -------------------------------------------------- выделения в тексте -- */
.mark {
  background: rgb(var(--hl-yellow) / var(--hl-a));
  border-bottom: 1px solid rgb(var(--hl-yellow-line) / var(--hl-line-a));
  border-radius: 2px;
  padding: .03em .02em .01em;
  cursor: pointer;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color .12s ease;
}
.mark--yellow { background: rgb(var(--hl-yellow) / var(--hl-a)); border-bottom-color: rgb(var(--hl-yellow-line) / var(--hl-line-a)); }
.mark--green { background: rgb(var(--hl-green) / var(--hl-a)); border-bottom-color: rgb(var(--hl-green-line) / var(--hl-line-a)); }
.mark--blue { background: rgb(var(--hl-blue) / var(--hl-a)); border-bottom-color: rgb(var(--hl-blue-line) / var(--hl-line-a)); }
.mark--pink { background: rgb(var(--hl-pink) / var(--hl-a)); border-bottom-color: rgb(var(--hl-pink-line) / var(--hl-line-a)); }
.mark:hover { background: rgb(var(--hl-yellow) / calc(var(--hl-a) + .14)); }
.mark--green:hover { background: rgb(var(--hl-green) / calc(var(--hl-a) + .14)); }
.mark--blue:hover { background: rgb(var(--hl-blue) / calc(var(--hl-a) + .14)); }
.mark--pink:hover { background: rgb(var(--hl-pink) / calc(var(--hl-a) + .14)); }

.flash {
  background: var(--accent-2);
  box-shadow: inset 0 -2px 0 var(--accent);
  border-radius: 2px;
  animation: flashFade 1.9s ease-out forwards;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
@keyframes flashFade {
  0% { background: rgb(var(--hl-yellow) / .85); box-shadow: inset 0 -2px 0 var(--accent); }
  55% { background: var(--accent-2); }
  100% { background: transparent; box-shadow: inset 0 -2px 0 transparent; }
}

/* --------------------------------------------------------- корешок ------ */
.spine {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 15px;
  z-index: 3;
  cursor: pointer;
}
.spine__track {
  position: absolute;
  top: 26px;
  bottom: 26px;
  right: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--rule);
}
.spine__fill {
  position: absolute;
  top: 26px;
  right: 0;
  width: 3px;
  height: 0;
  border-radius: 2px;
  background: var(--accent);
  pointer-events: none;
}
.spine__ticks { position: absolute; top: 26px; bottom: 26px; right: 3px; left: 0; pointer-events: none; }
.spine__tick {
  position: absolute;
  right: 5px;
  width: 7px;
  height: 1px;
  background: var(--ink-3);
  opacity: .45;
}
.spine__tick--l1 { width: 10px; opacity: .7; }
.spine__tick--l3 { width: 4px; opacity: .35; }
.spine__dot {
  position: absolute;
  right: -2px;
  width: 7px;
  height: 7px;
  margin-top: -3px;
  border-radius: 50%;
  background: rgb(var(--hl-yellow));
  box-shadow: 0 0 0 2px var(--paper);
}
.spine:hover .spine__tick { background: var(--accent); opacity: .9; }

.spine--hidden { display: none; }
@media (max-width: 1099px) { .spine { display: none; } }

/* --------------------------------------------- панель действий с выделением */
.seltool {
  position: fixed;
  z-index: 78;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 276px;
  max-width: min(520px, calc(100vw - 20px));
  padding: 10px 12px 11px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  animation: popIn .15s cubic-bezier(.2, .7, .3, 1);
}
.seltool[hidden] { display: none; }
.seltool__info {
  font-family: var(--font-ui);
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--ink-2);
}
.seltool--large .seltool__info { color: var(--danger); }
.seltool__row { display: flex; align-items: center; gap: 7px; }
.seltool__colors { display: flex; align-items: center; gap: 6px; }
.selcolor {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: rgb(var(--hl-yellow));
  cursor: pointer;
  transition: transform .1s ease;
}
.selcolor[data-color="yellow"] { background: rgb(var(--hl-yellow)); }
.selcolor[data-color="green"] { background: rgb(var(--hl-green)); }
.selcolor[data-color="blue"] { background: rgb(var(--hl-blue)); }
.selcolor[data-color="pink"] { background: rgb(var(--hl-pink)); }
.selcolor:hover { transform: scale(1.1); }
.selcolor:active { transform: scale(.96); }
.selcolor:disabled { opacity: .4; cursor: default; transform: none; }
.seltool__sep { width: 1px; height: 22px; background: var(--rule); margin: 0 2px; }
.seltool__act {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .12s ease;
}
.seltool__act:hover { background: var(--paper-2); }
.seltool__act--primary { background: var(--accent); border-color: var(--accent); color: #FFF; }
.seltool__act--primary:hover { background: var(--accent); filter: brightness(1.06); }
:root[data-theme="night"] .seltool__act--primary { color: #10201A; }
.seltool__act:disabled { opacity: .45; cursor: default; }

@keyframes popIn {
  from { opacity: 0; transform: scale(.96) translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* На узких экранах панель — полоса по низу окна, крупные кнопки. */
@media (max-width: 1279px) {
  .seltool {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    border-radius: 12px 12px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    gap: 9px;
    box-shadow: 0 -10px 34px rgba(17, 26, 21, .18);
  }
  .seltool__row { flex-wrap: wrap; row-gap: 9px; }
  .seltool__colors { flex: 1 1 100%; gap: 10px; }
  .selcolor { width: 40px; height: 40px; }
  .seltool__sep { display: none; }
  .seltool__act {
    flex: 1 1 42%;
    height: 44px;
    min-height: 44px;
    font-size: 13.5px;
  }
}

/* На тач-устройствах панель не прибита к низу: она рядом с выделением,
   снизу от него, с флипом вверх и запасом под браузерную полосу/панель ИИ. */
.is-touch .seltool {
  left: var(--sel-x, auto) !important;
  right: auto;
  top: var(--sel-y, auto) !important;
  bottom: auto;
  width: min(360px, calc(100vw - 16px));
  max-width: none;
  min-width: 0;
  padding: 10px 12px 11px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  gap: 8px;
}
.is-touch .seltool__row { flex-wrap: wrap; row-gap: 8px; }
.is-touch .seltool__colors { flex: 1 1 auto; gap: 10px; }
.is-touch .selcolor { width: 40px; height: 40px; }
.is-touch .seltool__sep { display: none; }
.is-touch .seltool__act {
  flex: 1 1 42%;
  height: 44px;
  min-height: 44px;
  font-size: 13.5px;
}

/* Подсказка при первом открытии книги «как сохранить выделение». */
.selhint {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 20px 0 4px;
  padding: 9px 8px 9px 12px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  background: var(--paper-2);
  font-family: var(--font-ui);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-2);
  text-align: left;
  hyphens: none;
}
.selhint__text { flex: 1 1 auto; }
.selhint__x {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.selhint__x:hover { background: var(--paper-3); color: var(--ink); }
.selhint__x .ic { width: 14px; height: 14px; }

/* Своё контекстное меню по правой кнопке на выделении. */
.ctxmenu { width: 252px; }

@media (max-width: 759px) {
  .selhint { font-size: 12px; margin-top: 12px; }
  .selhint__x { width: 40px; height: 40px; }
}

/* ----------------------------------------------- карточка заметки (popover) */
.pop {
  position: fixed;
  z-index: 82;
  width: 340px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 13px 14px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  color: var(--ink);
  font-family: var(--font-ui);
  animation: popIn .15s cubic-bezier(.2, .7, .3, 1);
}
.pop--dock {
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  top: auto !important;
  width: auto;
  max-height: 72vh;
}

.pop__quote {
  display: block;
  width: 100%;
  margin: 0 0 11px;
  padding: 0 0 0 11px;
  border: 0;
  border-left: 3px solid rgb(var(--hl) / 1);
  background: none;
  font-family: var(--font-read);
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink-2);
  text-align: left;
  hyphens: none;
  cursor: default;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}
button.pop__quote { cursor: pointer; }
button.pop__quote:hover { color: var(--ink); }

.pop__body {
  font-size: 13.5px;
  line-height: 1.52;
  color: var(--ink);
  margin: 0 0 11px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.pop__body--muted { color: var(--ink-2); font-style: italic; }
.pop__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-2);
  margin: 0 0 10px;
}
.pop__flag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 9px;
  background: var(--accent-2);
  color: var(--accent);
  font-size: 11px;
}
.pop__flag--warn { background: transparent; border: 1px solid var(--rule); color: var(--ink-2); }
.pop__acts { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.pop__acts .linkbtn { font-size: 12.5px; }
.pop__acts .spacer { flex: 1; }
.pop__x { width: 30px; height: 30px; }
.pop__x .ic { width: 14px; height: 14px; }

.pop__colors { display: flex; align-items: center; gap: 8px; margin: 0 0 11px; }
.pop__input {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.5;
}
.pop__input:focus { border-color: var(--accent); }
.pop__hint { font-size: 11.5px; color: var(--ink-2); }
.pop__name { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; font-size: 12.5px; color: var(--ink-2); }
.pop__name input { flex: 1; min-height: 34px; padding: 6px 9px; }

/* мобильная версия карточки */
@media (max-width: 759px) {
  .seltool { z-index: 79; }
  .pop { z-index: 83; }
  .notice__x { width: 40px; height: 40px; top: 2px; right: 2px; }
  .resume .btn--sm, .resume .mini { min-height: 40px; }
  .btn--sm { min-height: 40px; }
  .pop__acts .linkbtn { min-height: 40px; padding: 8px 2px; }
  .pop__x { width: 40px; height: 40px; }
}

/* ------------------------------------------------------- мобильный текст -- */
@media (max-width: 759px) {
  .reader { padding: 20px 0 96px; }
  .bookhead { margin-top: 8px; }
  .bookhead__title { font-size: 28px; }
  .bookhead__sub { font-size: 13.5px; }
  .chapter__title { font-size: 22px; }
  .chapter[data-level="2"] .chapter__title { font-size: 18px; }
  .chapter[data-level="3"] .chapter__title { font-size: 15px; }
  .chapter--part .chapter__title { font-size: 24px; }
  .chapter + .chapter { margin-top: 2.4em; }
  .chap-orn { margin-bottom: 1.8em; }
  .notice { font-size: 12.5px; margin-top: 20px; }
  .resume { font-size: 12.5px; padding: 10px 11px; }
  .book-end { margin-top: 3.2em; }
}
