/* ============================================================
   NovaLibre — режим чтения
   Полноэкранный overlay с оптимизированной типографикой
   ============================================================ */

.reader-overlay {
  position: fixed;
  inset: 0;
  z-index: 7000;
  background: var(--reader-bg-color, var(--reader-bg));
  color: var(--reader-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: readerFadeIn 0.25s ease-out;
}

@keyframes readerFadeIn {
  from { opacity: 0; transform: scale(0.99); }
  to { opacity: 1; transform: scale(1); }
}

/* Тулбар */
.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: var(--reader-bg-color, var(--reader-bg));
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.reader-toolbar .btn-icon {
  color: var(--reader-text-secondary);
  width: 36px;
  height: 36px;
}

.reader-toolbar .btn-icon:hover {
  background: rgba(128, 128, 128, 0.15);
  color: var(--reader-text);
}

.reader-toolbar .btn-icon.active {
  color: var(--reader-link);
}

.reader-toolbar .spacer {
  flex: 1;
}

/* Контентная область */
.reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 24px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  scrollbar-width: thin;
  scrollbar-color: rgba(128,128,128,0.3) transparent;
  transition: max-width 0.2s, padding 0.2s;
}

.reader-content::-webkit-scrollbar {
  width: 8px;
}
.reader-content::-webkit-scrollbar-thumb {
  background: rgba(128,128,128,0.3);
  border-radius: 4px;
}

.reader-content[data-width="narrow"] { max-width: 580px; }
.reader-content[data-width="medium"] { max-width: 720px; }
.reader-content[data-width="wide"] { max-width: 920px; }

/* Мета-информация */
.reader-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--reader-text-secondary);
}

.reader-meta img {
  width: 20px;
  height: 20px;
  border-radius: 4px;
}

.reader-meta .reader-source {
  font-weight: 500;
  color: var(--reader-text);
}

.reader-meta .reader-date {
  color: var(--reader-text-secondary);
}

/* Заголовок */
.reader-title {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 12px;
  color: var(--reader-text);
  letter-spacing: -0.5px;
}

.reader-author {
  font-size: 14px;
  color: var(--reader-text-secondary);
  margin-bottom: 24px;
  font-style: italic;
}

/* Тело статьи */
.reader-body {
  font-size: var(--reader-font-size, 18px);
  line-height: var(--reader-line-height, 1.7);
  font-family: var(--reader-font-family, var(--font-serif));
  color: var(--reader-text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.reader-body[data-font-family="serif"] { font-family: var(--font-serif); }
.reader-body[data-font-family="sans"] { font-family: var(--font-ui); }
.reader-body[data-font-family="mono"] { font-family: var(--font-mono); }
.reader-body[data-font-family="wenkai"] { font-family: var(--font-wenkai); }

/* Типографика внутри статьи */
.reader-body p {
  margin: 0 0 1.2em;
}

.reader-body h1,
.reader-body h2,
.reader-body h3,
.reader-body h4,
.reader-body h5,
.reader-body h6 {
  color: var(--reader-text);
  font-weight: 700;
  margin: 1.6em 0 0.8em;
  line-height: 1.3;
}

.reader-body h1 { font-size: 1.6em; }
.reader-body h2 { font-size: 1.4em; }
.reader-body h3 { font-size: 1.2em; }
.reader-body h4 { font-size: 1.05em; }

.reader-body a {
  color: var(--reader-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.15s;
}

.reader-body a:hover {
  color: var(--reader-text);
}

.reader-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1em 0;
  display: block;
}

.reader-body figure {
  margin: 1.5em 0;
  text-align: center;
}

.reader-body figcaption {
  font-size: 0.85em;
  color: var(--reader-text-secondary);
  margin-top: 8px;
  font-style: italic;
}

.reader-body blockquote {
  margin: 1.5em 0;
  padding: 0.5em 1em;
  border-left: 3px solid var(--reader-link);
  color: var(--reader-text-secondary);
  font-style: italic;
}

.reader-body pre {
  background: rgba(128,128,128,0.1);
  padding: 14px 18px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.9em;
  font-family: var(--font-mono);
  margin: 1.2em 0;
}

.reader-body code {
  font-family: var(--font-mono);
  background: rgba(128,128,128,0.12);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.88em;
}

.reader-body pre code {
  background: transparent;
  padding: 0;
}

.reader-body ul,
.reader-body ol {
  margin: 1em 0;
  padding-left: 1.6em;
}

.reader-body li {
  margin: 0.4em 0;
}

.reader-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.92em;
}

.reader-body th,
.reader-body td {
  padding: 8px 12px;
  border: 1px solid rgba(128,128,128,0.25);
  text-align: left;
}

.reader-body th {
  background: rgba(128,128,128,0.1);
  font-weight: 600;
}

.reader-body hr {
  border: none;
  border-top: 1px solid rgba(128,128,128,0.25);
  margin: 2em 0;
}

.reader-body strong {
  font-weight: 700;
  color: var(--reader-text);
}

.reader-body em {
  font-style: italic;
}

.reader-body mark {
  background: rgba(255, 200, 0, 0.35);
  padding: 0 2px;
  border-radius: 2px;
}

/* Изображения-обложки */
.reader-cover {
  width: 100%;
  max-height: 380px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 24px;
}

/* Подвал статьи */
.reader-footer {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid rgba(128,128,128,0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.reader-footer-actions {
  display: flex;
  gap: 8px;
}

.reader-footer .btn {
  background: rgba(128,128,128,0.12);
  color: var(--reader-text);
  border: 1px solid rgba(128,128,128,0.2);
}

.reader-footer .btn:hover {
  background: rgba(128,128,128,0.2);
}

/* Навигация между статьями */
.reader-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(128,128,128,0.15);
}

.reader-nav button {
  flex: 1;
  padding: 12px 16px;
  background: rgba(128,128,128,0.1);
  border: 1px solid rgba(128,128,128,0.2);
  border-radius: 8px;
  color: var(--reader-text);
  font-size: 14px;
  text-align: left;
  transition: all 0.15s;
}

.reader-nav button:hover:not(:disabled) {
  background: rgba(128,128,128,0.2);
  border-color: var(--reader-link);
}

.reader-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.reader-nav .nav-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--reader-text-secondary);
  letter-spacing: 0.5px;
}

.reader-nav .nav-title {
  font-weight: 500;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-nav .nav-next {
  text-align: right;
}

/* Прогресс чтения */
.reader-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--reader-link);
  z-index: 11;
  transition: width 0.05s;
}

/* ============================================================
   Адаптация под мобильные
   ============================================================ */

@media (max-width: 768px) {
  .reader-content {
    padding: 24px 16px;
  }

  .reader-title {
    font-size: 24px;
  }

  .reader-body {
    font-size: calc(var(--reader-font-size, 18px) - 1px);
  }

  .reader-toolbar {
    padding: 6px 10px;
  }

  .reader-toolbar .btn-icon {
    width: 32px;
    height: 32px;
  }

  .reader-content[data-width="narrow"],
  .reader-content[data-width="medium"],
  .reader-content[data-width="wide"] {
    max-width: 100%;
  }

  .reader-nav {
    flex-direction: column;
  }

  .reader-nav .nav-next {
    text-align: left;
  }
}

/* Анимация появления картинок */
.reader-body img {
  opacity: 0;
  transition: opacity 0.3s;
}

.reader-body img loaded,
.reader-body img[src][src]:not([src=""]) {
  opacity: 1;
}

/* Скрыть скроллбар на мобильных */
@media (hover: none) {
  .reader-content::-webkit-scrollbar {
    display: none;
  }
}

/* ============================================================
   Reading progress bar
   ============================================================ */

#reader-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 11;
  pointer-events: none;
}

#reader-progress .progress-bar {
  height: 100%;
  background: var(--reader-link, var(--accent));
  width: 0;
  transition: width 0.1s ease-out;
}
