/* ============================================================
 *  ЧИТАЛКА — стили 1:1 с ридером Author.Today
 *  (значения сняты с оригинального /dist/css/reader)
 * ============================================================ */

/* ---- Переменные, которыми управляют «Настройки» ---- */
:root {
  --r-bg:        #ffffff;   /* фон страницы / схема яркости  */
  --r-fg:        #444444;   /* цвет текста интерфейса        */
  --r-text:      #1a1a1a;   /* цвет текста главы            */
  --r-muted:     #999999;   /* приглушённый текст           */
  --r-line:      #cccccc;   /* разделители/границы шапки     */
  --r-accent:    #4582af;   /* акцент (ссылки, активное)    */

  --r-btn-bd:    #95a5a6;   /* рамка кнопок шапки           */
  --r-btn-fg:    #444444;   /* текст кнопок                 */
  --r-btn-hbg:   #7f8c8d;   /* фон кнопок при наведении      */
  --r-btn-hfg:   #ffffff;   /* текст кнопок при наведении    */

  --r-font:        Roboto, "Helvetica Neue", Arial, sans-serif;
  --r-size:        18px;    /* размер шрифта главы          */
  --r-line-height: 1.5;     /* высота строк                 */
  --r-maxw:        800px;   /* ширина колонки («Поля»)       */
  --r-brightness:  1;       /* доп. затемнение (свои цвета)  */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--r-bg);
  color: var(--r-text);
  font-family: Roboto, "-apple-system", BlinkMacSystemFont, Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s, color .25s;
}

a { color: var(--r-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Затемнение для своих цветовых схем */
#brightness-veil {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: calc(1 - var(--r-brightness));
  pointer-events: none;
  z-index: 60;
  transition: opacity .15s linear;
}

/* ============================================================
 *  ВЕРХНЯЯ ПАНЕЛЬ  (.reader-header в оригинале)
 * ============================================================ */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--r-bg);
  border-bottom: 1px solid var(--r-line);
  z-index: 50;
  transition: transform .25s ease, opacity .25s ease, background-color .25s;
}
.toolbar__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 20px;
}
.toolbar__left,
.toolbar__right { display: flex; align-items: center; gap: 5px; min-width: 0; }

/* ---- Кнопки шапки = .btn .btn-brd .btn-with-icon ---- */
.tbtn {
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 12px;
  border: 1px solid var(--r-btn-bd);
  background: none;
  color: var(--r-btn-fg);
  border-radius: 4px;
  cursor: pointer;
  font: 400 14px/1.6 Roboto, "-apple-system", BlinkMacSystemFont, Tahoma, Arial, sans-serif;
  white-space: nowrap;
  transition: background-color .1s ease-in-out, color .1s ease-in-out, border-color .1s ease-in-out;
}
.tbtn:hover { background: var(--r-btn-hbg); color: var(--r-btn-hfg); border-color: var(--r-btn-hbg); }
.tbtn.is-active { background: var(--r-btn-hbg); color: var(--r-btn-hfg); border-color: var(--r-btn-hbg); }
.tbtn .ic { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.tbtn__txt { overflow: hidden; text-overflow: ellipsis; }

/* Иконочные кнопки (книжный режим / фуллскрин) — квадратные 32×32 */
.tbtn--ico { width: 32px; padding: 0; }

/* Переключение иконки «Оглавление» ↔ «закрыть» */
.tbtn .ic-chev { display: none; }
body.menu-open #btn-toc .ic-list { display: none; }
body.menu-open #btn-toc .ic-chev { display: inline; }
/* Когда оглавление открыто — левые кнопки сжимаются в иконки «‹ / домой» (как на АТ),
   а шапка сдвигается вправо, освобождая место под панель */
body.menu-open .toolbar__left .tbtn__txt { display: none; }
body.menu-open .toolbar__left .tbtn { width: 32px; padding: 0; }
body.menu-open .toolbar { left: 470px; z-index: 90; }

.tbtn--more { display: none; }   /* кнопка «ещё» — только на мобиле */
.ic-back { display: none; }       /* стрелка «назад» — только на мобиле */

body.chrome-hidden .toolbar { transform: translateY(-100%); opacity: 0; }

/* Меню «Ещё» (мобайл): книжный режим / во весь экран */
.more-menu {
  position: fixed; top: 50px; right: 8px;
  min-width: 210px; background: var(--r-bg); color: var(--r-fg);
  border: 1px solid var(--r-line); border-radius: 10px;
  box-shadow: 0 6px 22px rgba(0,0,0,.22); padding: 6px; z-index: 82;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
.more-menu.is-open { opacity: 1; visibility: visible; transform: translateY(0); }
.more-menu button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 12px; border: none; background: none; color: var(--r-fg);
  font: 500 15px/1 Roboto, "-apple-system", Arial, sans-serif; cursor: pointer; border-radius: 7px;
}
.more-menu button:hover { background: rgba(0,0,0,.06); }
.more-menu .ic { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
body.scheme-dark .more-menu { background: #232323; border-color: #2c2c2c; }
body.scheme-dark .more-menu button:hover { background: rgba(255,255,255,.08); }

/* ============================================================
 *  ОБЛАСТЬ ЧТЕНИЯ
 * ============================================================ */
.reader {
  padding: 53px 0 0;
  min-height: 100%;
}
.reader__inner {
  max-width: var(--r-maxw);
  margin: 0 auto;
  padding: 40px 15px 120px;
  font-size: var(--r-size);
  line-height: var(--r-line-height);
  color: var(--r-text);
}
.reader__chapter-title {
  font-weight: 700;
  font-size: 1.4em;
  text-align: center;
  margin: 0 0 1.4em;
  color: var(--r-text);
}
.reader__body { text-align: justify; }
.reader__body p {
  margin: 0 0 7px;
  padding-right: 1px;
  text-indent: 2em;
  word-break: break-word;
}
/* Перенос текста (расстановка переносов) */
body.hyphenate .reader__body p {
  -webkit-hyphens: auto;
  hyphens: auto;
}

/* ---- Нижний пейджер по главам (.pager в оригинале) ---- */
.chap-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--r-maxw);
  margin: 0 auto;
  padding: 0 15px 50px;
}
.chap-nav a {
  flex: 0 1 auto;
  max-width: 48%;
  padding: 8px 16px;
  background: var(--r-bg);
  border: 1px solid #ddd;
  border-radius: 19px;
  color: var(--r-text);
  font-size: 17px;
  overflow-wrap: break-word;
  transition: background .15s, border-color .15s;
}
.chap-nav a:hover { text-decoration: none; border-color: var(--r-btn-bd); }
.chap-nav a.is-disabled { opacity: .35; pointer-events: none; }

/* ============================================================
 *  КНИЖНЫЙ РЕЖИМ (постранично, как книга)
 * ============================================================ */
body.book-mode .reader { padding-top: 53px; height: 100vh; overflow: hidden; }
body.book-mode .reader__inner {
  height: calc(100vh - 53px);
  max-width: none;
  padding: 40px 80px 60px;
  column-width: var(--r-maxw);
  column-gap: 80px;
  column-fill: auto;
  overflow: hidden;
  transition: transform .25s ease;
}
body.book-mode .chap-nav { display: none; }
.page-tap {
  position: fixed;
  top: 53px; bottom: 0;
  width: 80px;
  z-index: 40;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--r-muted);
  opacity: 0;
  transition: opacity .3s;
}
.page-tap:hover { opacity: 1; }
.page-tap svg { width: 22px; height: 44px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.page-tap--left  { left: 0; }
.page-tap--right { right: 0; }
body.book-mode .page-tap { display: flex; }
.page-counter {
  position: fixed;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--r-muted);
  z-index: 45;
  display: none;
}
body.book-mode .page-counter { display: block; }

/* ============================================================
 *  ЛЕВАЯ ПАНЕЛЬ — оглавление + карточка книги (.aside в оригинале)
 * ============================================================ */
.scrim {
  position: fixed; inset: 0;
  background: transparent;
  opacity: 0; visibility: hidden;
  transition: visibility .25s;
  z-index: 70;
}
.scrim.is-open { opacity: 1; visibility: visible; }
/* При открытом оглавлении основная область затемняется (как на АТ) */
body.menu-open .scrim { background: rgba(0,0,0,.4); transition: opacity .25s, visibility .25s; }

.drawer--left {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 470px;
  max-width: 100%;
  background: var(--r-bg);
  color: var(--r-fg);
  transform: translateX(-100%);
  transition: transform .25s;
  z-index: 80;
  overflow-x: hidden;
  overflow-y: auto;
}
.drawer--left.is-open { transform: translateX(0); }
.drawer__body { padding: 0; }

/* ---- Карточка книги (.book-row) — обложка floated, текст обтекает ---- */
.book-card { padding: 30px 30px 0; margin-bottom: 6px; }
.book-card::after { content: ""; display: block; clear: both; }
.book-card__cover-link { float: left; width: 140px; margin: 4px 18px 12px 0; display: block; }
.book-card__cover {
  width: 140px; aspect-ratio: 2/3; object-fit: cover;
  border-radius: 4px; background: var(--r-line); display: block;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.book-card__title { margin: 0 0 6px; font-size: 22px; line-height: 1.2; font-weight: 400; }
.book-card__title a { color: var(--r-fg); }
.book-card__title a:hover { color: var(--r-accent); text-decoration: none; }
.book-card__author { margin: 0 0 8px; font-size: 14px; }
.book-card__author a { color: var(--r-muted); }
.book-card__author a:hover { color: var(--r-accent); }
.book-card__genres { font-size: 13px; line-height: 1.45; margin-bottom: 10px; }
.book-card__genres a { color: var(--r-accent); }
.book-card__genres .sep { color: var(--r-muted); }

.book-card__meta { margin: 0 0 8px; font-size: 13px; line-height: 1.55; }
.book-card__meta .row { display: flex; gap: 5px; }
.book-card__meta .k { color: var(--r-muted); }
.book-card__meta .v { color: var(--r-fg); }
.book-card__meta .v.dotted { border-bottom: 1px dotted var(--r-muted); cursor: help; }
.book-card__meta .status { color: #2e9e54; display: inline-flex; align-items: center; gap: 4px; }
.book-card__meta .status svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2.4; }

/* Теги — компактный интерлиньяж */
.book-card__tags { font-size: 13px; line-height: 1.4; margin-bottom: 0; }
.book-card__tags .tag-ico { display: inline-block; margin-right: 5px; vertical-align: -2px; }
.book-card__tags .tag-svg { width: 14px; height: 14px; stroke: var(--r-muted); fill: none; stroke-width: 1.7; stroke-linejoin: round; }
.book-card__tags a { color: var(--r-accent); }

/* Статистика — отдельной строкой во всю ширину панели */
.book-card__stats {
  clear: both;
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
  font-size: 13px; color: var(--r-muted);
  padding: 16px 0 14px;
}
.book-card__stats .st { display: inline-flex; align-items: center; gap: 5px; color: var(--r-muted); }
a.st:hover { color: var(--r-accent); text-decoration: none; }
.book-card__stats svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.7; }

/* «Читать» = .btn .btn-default (белая, серая рамка) */
.book-card__read {
  display: block; width: max-content; max-width: 100%; text-align: center;
  margin: 0 auto 4px;
  padding: 6px 22px; border: 1px solid #cccccc; border-radius: 4px;
  background: #ffffff; color: #333333; font-size: 14px;
  transition: background-color .15s, border-color .15s;
}
.book-card__read:hover { background: #e6e6e6; border-color: #adadad; color: #333333; text-decoration: none; }
body.scheme-dark .book-card__read { background: transparent; color: #dddddd; border-color: #ffffff; }
body.scheme-dark .book-card__read:hover { background: rgba(255,255,255,.12); color: #ffffff; border-color: #ffffff; }

/* ---- Содержание (.contents) ---- */
.contents { padding: 20px 30px 60px; }
.contents h2 { margin: 0 0 25px 10px; padding: 0; font-size: 24px; font-weight: 400; color: var(--r-fg); }
.toc__list { list-style: none; margin: 0; padding: 0 0 20px 5px; border-top: 1px solid #ececec; }
.toc__item a {
  display: block;
  position: relative;
  margin: 0;
  padding: 15px 10px 15px 18px;
  color: var(--r-fg);
  font-size: 15px;
  border-bottom: 1px solid #ececec;
}
.toc__item a:hover { background: rgba(241,241,241,.5); color: #000; text-decoration: none; }
.toc__item.is-current a { font-weight: 700; }
.toc__item.is-current a::before {
  content: ""; position: absolute; left: -10px; top: 50%;
  margin-top: -6px;
  border: 6px solid transparent; border-right: 0;
  border-left: 9px solid currentColor;
}
body.scheme-dark .toc__list,
body.scheme-dark .toc__item a { border-color: #2c2c2c; }
body.scheme-dark .toc__item a:hover { background: rgba(255,255,255,.06); color: #fff; }

/* ============================================================
 *  НАСТРОЙКИ — выпадающее меню под кнопкой (.drop.reader-menu)
 * ============================================================ */
.reader-menu {
  position: fixed;
  top: 50px; right: 15px;
  width: 350px;
  max-width: calc(100vw - 20px);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--r-bg);
  color: var(--r-fg);
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: 0 3px 10px 0 rgba(0,0,0,.3);
  padding: 20px 10px;
  z-index: 80;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
.reader-menu.is-open { opacity: 1; visibility: visible; transform: translateY(0); }
/* В тёмных схемах меню/попап — #232323 (как .tether-drop-content на АТ) */
body.scheme-dark .reader-menu { background: #232323; border-color: #2c2c2c; box-shadow: none; }
body.scheme-dark .menu-slider { background: #4a4a4a; }

.menu-item { display: flex; align-items: center; margin-bottom: 20px; }
.menu-item__cap {
  flex: 0 0 25%;
  text-align: center;
  color: var(--r-fg);
}
/* Иконка-подпись: SVG или буквенный глиф (как в иконочном шрифте АТ) */
.cap-ico { display: block; height: 24px; line-height: 24px; }
.cap-ico svg { width: 22px; height: 22px; vertical-align: middle; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.cap-ico--aa { font: 700 20px/24px Roboto, Arial, sans-serif; }
.cap-ico--aa small { font-size: 13px; }
.cap-ico--serif { font: 400 24px/24px Georgia, "Times New Roman", serif; }
.menu-item__cap .cap-text { display: block; font-size: 13px; line-height: 1.2; margin-top: 2px; }
.menu-item__content { flex: 0 0 75%; padding: 0 10px; }
.menu-item__val { float: right; font-size: 13px; color: var(--r-muted); font-variant-numeric: tabular-nums; }

/* Ползунки (как kendo-слайдеры на АТ): синяя заливка слева + белый кружок */
.menu-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 3px;
  background: #e0e0e0;          /* перекрывается inline-градиентом из JS */
  outline: none; margin: 16px 0 4px;
}
.menu-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: #ffffff; cursor: pointer; border: 1px solid #b9b9b9;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); margin-top: -6px;
}
.menu-slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: transparent; }
.menu-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: #ffffff; cursor: pointer; border: 1px solid #b9b9b9;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.menu-slider::-moz-range-track { height: 6px; border-radius: 3px; background: #e0e0e0; }
.menu-slider::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--r-accent); }
body.scheme-dark .menu-slider::-moz-range-track { background: #4a4a4a; }

/* Выбор шрифта (.font-picker) */
.font-picker { padding: 0 25px 0 15px; font-size: 18px; line-height: 40px; }
.current-font { cursor: pointer; text-align: center; position: relative; }
.current-font .caret { position: absolute; top: 0; right: -16px; font-size: 12px; color: var(--r-muted); }
.current-font:hover { color: var(--r-accent); }
.font-list { list-style: none; padding: 0; margin: 6px 0 0; text-align: center; }
.font-list li { cursor: pointer; line-height: 32px; }
.font-list li:hover { color: var(--r-accent); }
.font-list li.is-active { color: var(--r-accent); }
.font-list[hidden] { display: none; }

/* Чекбоксы (.checkbox c-checkbox) */
.menu-check { display: flex; align-items: center; gap: 10px; margin: 0 10px 20px; cursor: pointer; font-size: 14px; }
.menu-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.menu-check .box {
  width: 18px; height: 18px; flex: 0 0 auto;
  border: 1px solid var(--r-btn-bd); border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
}
.menu-check .box svg { width: 12px; height: 12px; stroke: #fff; fill: none; stroke-width: 3; opacity: 0; }
.menu-check input:checked + .box { background: var(--r-accent); border-color: var(--r-accent); }
.menu-check input:checked + .box svg { opacity: 1; }

/* Свои цвета (Spectrum-аналог): подписи в одну строку, образцы выровнены */
.menu-colors[hidden] { display: none; }
.menu-colors { padding: 4px 10px 0; }
.color-row { display: flex; align-items: center; margin-bottom: 12px; }
.color-row__label { flex: 0 0 110px; font-size: 14px; color: var(--r-fg); white-space: nowrap; }
.swatch {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid #cccccc; border-radius: 3px; padding: 3px 6px 3px 4px;
  background: #fff;
}
.swatch input[type="color"] {
  width: 40px; height: 22px; border: 1px solid #d6d6d6;
  border-radius: 2px; background: transparent; cursor: pointer; padding: 0;
}
.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: 1px; }
.swatch .caret { font-size: 11px; color: var(--r-muted); }
body.scheme-dark .swatch { background: #2c2c2c; border-color: #444; }

/* ============================================================
 *  ЛЕНДИНГ КНИГИ (index.php — страница-прокладка)
 * ============================================================ */
.landing-body { background: #f3f4f6; }
.landing { max-width: 780px; margin: 0 auto; padding: 30px 16px 60px; }
.landing .book-card,
.landing .contents {
  background: #fff; border-radius: 12px; box-shadow: 0 2px 14px rgba(0,0,0,.06);
}
.book-card--landing { padding: 28px 28px 22px; margin-bottom: 18px; }
.book-card--landing .book-card__cover-link { width: 170px; margin: 4px 24px 14px 0; }
.book-card--landing .book-card__cover { width: 170px; }
.book-card--landing .book-card__title { font-size: 26px; margin-bottom: 8px; }
.landing-read {
  margin: 4px 0 0 !important; width: auto !important; display: inline-block !important;
  padding: 11px 34px !important; font-size: 16px !important; font-weight: 500;
  background: var(--r-accent) !important; color: #fff !important; border-color: var(--r-accent) !important;
}
.landing-read:hover { background: #3a6f97 !important; border-color: #3a6f97 !important; color: #fff !important; }
.landing-contents { padding: 6px 28px 30px; }
.landing-contents h2 { margin: 18px 0 18px 10px; }

/* ============================================================
 *  Адаптив
 * ============================================================ */
@media (max-width: 767px) {
  .landing { padding: 14px 10px 40px; }
  .book-card--landing { padding: 20px 18px 18px; }
  .book-card--landing .book-card__cover-link { width: 130px; margin-right: 16px; }
  .book-card--landing .book-card__cover { width: 130px; }
  .book-card--landing .book-card__title { font-size: 22px; }
  /* ---- Шапка как в мобильном ридере АТ: синяя плашка, белые иконки ---- */
  .toolbar { background: #4585ad; border-bottom: none; }
  .toolbar__nav { padding: 6px; gap: 2px; }
  .toolbar .tbtn__txt { display: none; }
  .toolbar .tbtn {
    width: 42px; height: 42px; padding: 0;
    color: #fff; background: transparent; border-color: transparent;
  }
  .toolbar .tbtn:hover, .toolbar .tbtn.is-active { background: rgba(255,255,255,.18); color: #fff; border-color: transparent; }
  .toolbar .tbtn .ic { width: 22px; height: 22px; }

  /* Все кнопки в один ряд, порядок: ←  …  ⚙ ☰ ⋮ */
  .toolbar__left, .toolbar__right { display: contents; }
  #btn-home     { order: 0; margin-right: auto; }
  #btn-settings { order: 1; }
  #btn-toc      { order: 2; }
  #btn-more     { order: 3; display: inline-flex; }
  #btn-bookmode, #btn-fullscreen { display: none; }   /* уехали в «Ещё» */
  #btn-home .ic-home { display: none; }
  #btn-home .ic-back { display: inline; }
  body.menu-open .toolbar { left: 0; z-index: 90; }   /* не сдвигаем шапку */
  body.menu-open .toolbar__left .tbtn { width: 42px; }
  .more-menu { right: 6px; top: 54px; }

  /* Содержание — на весь экран, под шапкой */
  .drawer--left { width: 100%; top: 53px; }

  /* Настройки — нижняя шторка (bottom sheet), как на АТ */
  .reader-menu {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-width: 100%;
    border-radius: 16px 16px 0 0; max-height: 80vh;
    padding: 18px 14px 26px; transform: translateY(100%);
    box-shadow: 0 -8px 30px rgba(0,0,0,.25);
  }
  .reader-menu.is-open { transform: translateY(0); }
  body.settings-open .scrim { background: rgba(0,0,0,.4); transition: opacity .25s, visibility .25s; }

  .reader__inner { padding: 30px 15px 100px; }
  body.book-mode .reader__inner { padding: 30px 30px 50px; }
  .page-tap { width: 30%; }
}
