/*
 * Chapter reader (/bible-reader) — visual layer matching verse commentary Stitch.
 * Open /bible-reader?design=legacy for the previous look.
 */

.reader-chapter-stitch-design {
  --stitch-card-bg: hsl(95 10% 95.5%);
  --stitch-card-border: hsl(95 10% 78% / 0.55);
  --stitch-card-top: hsl(var(--gold-dark) / 0.62);
  --stitch-card-shadow:
    0 1px 0 hsl(90 20% 99% / 0.55) inset,
    0 0.55rem 1.35rem hsl(100 8% 20% / 0.03);
  --stitch-verse-shell: hsl(40 38% 95%);
  color: hsl(var(--verse-stitch-ink, var(--foreground)));
}

/* Полоса «← Назад» — как на странице толкований */
.reader-chapter-stitch-design > .reader-chapter-top-nav {
  display: flex;
  align-items: center;
  width: 100vw;
  max-width: 100vw;
  box-sizing: border-box;
  position: relative;
  left: 50%;
  margin: 0 0 1.25rem;
  margin-left: -50vw;
  margin-right: -50vw;
  padding: 0.72rem max(1rem, calc(50vw - min(50vw - 1rem, 680px)));
  border: 0;
  border-bottom: 1px solid hsl(35 20% 84% / 0.85);
  background: hsl(36 30% 94.5%);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.reader-chapter-stitch-design > .reader-chapter-top-nav .section-back-link {
  color: hsl(var(--gold-dark));
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
}

.reader-chapter-stitch-design > .reader-chapter-top-nav .section-back-link:hover {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.reader-chapter-stitch-design > .bible-reader-header {
  margin-top: 0;
  margin-bottom: 0.85rem;
}

.reader-chapter-stitch-design .bible-reader-header .section-settings-title-inline {
  color: hsl(var(--gold-dark));
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.45rem, 3vw, 1.75rem);
  letter-spacing: 0.02em;
}

body.dark .reader-chapter-stitch-design .bible-reader-header .section-settings-title-inline {
  color: hsl(var(--gold-light));
}

/* Колонка стихов — прозрачная на пергаменте, без «карточки» legacy */
.reader-chapter-stitch-design .verses-section {
  background: transparent;
  border: 0;
  border-radius: 0;
  margin-left: 0;
  padding-top: 0.35rem;
}

.reader-chapter-stitch-design.timeline-user-hidden .verses-section {
  border-radius: 0;
}

.reader-chapter-stitch-design .timeline-sidebar {
  background: hsl(95 10% 95.5% / 0.72);
  border-color: hsl(95 10% 78% / 0.45);
  border-top: 2px solid var(--stitch-card-top);
}

/* Поиск */
.reader-chapter-stitch-design .verses-section-toolbar {
  margin-bottom: 0.85rem;
}

.reader-chapter-stitch-design .verse-search-form {
  flex: 1;
  min-width: 0;
  border: 1px solid hsl(var(--border) / 0.65);
  border-radius: 999px;
  background: hsl(40 38% 95% / 0.85);
  box-shadow: 0 1px 0 hsl(90 20% 99% / 0.4) inset;
}

.reader-chapter-stitch-design .verse-search-input {
  background: transparent;
  border: 0;
  color: hsl(var(--foreground));
  font-family: var(--font-body);
  font-size: 0.92rem;
}

.reader-chapter-stitch-design .verse-search-input::placeholder {
  color: hsl(var(--muted-foreground));
}

.reader-chapter-stitch-design .verse-search-input:focus {
  outline: none;
  box-shadow: none;
}

.reader-chapter-stitch-design .verse-search-btn {
  border: 0;
  border-radius: 999px;
  background: hsl(var(--gold-dark));
  color: hsl(40 33% 97%);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  min-height: 2.15rem;
  padding: 0 1rem;
}

.reader-chapter-stitch-design .verse-search-btn:hover,
.reader-chapter-stitch-design .verse-search-btn:focus-visible {
  background: hsl(var(--gold));
  color: hsl(25 20% 12%);
}

.reader-chapter-stitch-design .verse-search-clear-btn {
  color: hsl(var(--muted-foreground));
  min-width: 2.25rem;
  min-height: 2.25rem;
}

.reader-chapter-stitch-design .timeline-mobile-trigger {
  border: 1px solid hsl(95 10% 78% / 0.55);
  border-top: 2px solid var(--stitch-card-top);
  border-radius: 0.55rem;
  background: var(--stitch-card-bg);
  color: hsl(var(--gold-dark));
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Заголовки книг/глав */
.reader-chapter-stitch-design .verse-book-heading,
.reader-chapter-stitch-design .verse-chapter-heading {
  font-family: var(--font-display);
  font-weight: 600;
}

/* Список стихов */
.reader-chapter-stitch-design .verse-list {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.2vw, 1.2rem);
  line-height: 1.62;
  color: hsl(25 35% 0%);
}

.reader-chapter-stitch-design .verse-num {
  color: hsl(var(--gold-dark));
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.reader-chapter-stitch-design .verse-item {
  border-bottom: 1px solid hsl(var(--border) / 0.35);
  border-radius: 0.55rem;
  padding: 0.55rem 0.65rem 0.55rem 0;
  margin-right: 0;
  transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.reader-chapter-stitch-design .verse-item:hover {
  background: var(--stitch-card-bg);
  box-shadow: var(--stitch-card-shadow);
  border-bottom-color: transparent;
  border-left: 3px solid hsl(var(--gold-dark) / 0.45);
  padding-left: calc(0.65rem - 3px);
}

.reader-chapter-stitch-design .verse-item.verse-item--row-menu-active,
.reader-chapter-stitch-design .verse-item.is-target {
  background: var(--stitch-card-bg);
  border: 1px solid var(--stitch-card-border);
  border-top: 3px solid var(--stitch-card-top);
  border-bottom-color: var(--stitch-card-border);
  border-radius: 0.7rem;
  box-shadow: var(--stitch-card-shadow);
  padding: 0.65rem 0.85rem 0.65rem calc(0.85rem - 3px);
  margin: 0.15rem 0;
}

.reader-chapter-stitch-design .verse-item.verse-item--row-menu-active {
  border-left: 3px solid hsl(var(--gold-dark) / 0.85);
}

.reader-chapter-stitch-design .verse-item.verse-item--has-bookmark > .verse-item-row {
  border-radius: 0.45rem;
  background: linear-gradient(90deg, hsl(var(--gold) / 0.22) 0%, transparent 70%);
  box-shadow: inset 3px 0 0 0 hsl(var(--gold-dark) / 0.75);
}

.reader-chapter-stitch-design .verse-footnote-marker {
  color: hsl(var(--gold-dark));
}

/* Контекстное меню стиха — зеленоватая карточка толкований */
body:has(.reader-chapter-stitch-design) .verse-row-menu {
  min-width: 260px;
  padding: 0.35rem 0 0.45rem;
  border: 1px solid var(--stitch-card-border);
  border-top: 3px solid var(--stitch-card-top);
  border-radius: 0.7rem;
  background: var(--stitch-card-bg);
  box-shadow: var(--stitch-card-shadow), 0 0.75rem 2rem hsl(100 8% 20% / 0.08);
}

body:has(.reader-chapter-stitch-design) .verse-row-menu-item {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0.45rem 1rem;
  color: hsl(25 28% 14%);
  font-family: var(--font-body);
  font-size: 0.88rem;
}

body:has(.reader-chapter-stitch-design) .verse-row-menu-item--with-icon {
  padding: 0.45rem 0.85rem 0.45rem 1rem;
}

body:has(.reader-chapter-stitch-design) .verse-row-menu-item:hover:not(:disabled),
body:has(.reader-chapter-stitch-design) .verse-row-menu-item:focus-visible:not(:disabled) {
  background: hsl(95 12% 91%);
  color: hsl(var(--gold-dark));
}

body:has(.reader-chapter-stitch-design) .verse-row-menu-icon,
body:has(.reader-chapter-stitch-design) .verse-row-menu-chevron {
  color: hsl(var(--gold-dark));
}

body:has(.reader-chapter-stitch-design) .verse-row-menu-hl-sub {
  border: 1px solid var(--stitch-card-border);
  border-top: 3px solid var(--stitch-card-top);
  border-radius: 0.7rem;
  background: var(--stitch-card-bg);
  box-shadow: var(--stitch-card-shadow);
}

/* Иллюстрации к главе — карточка только когда слайдер развёрнут */
.reader-chapter-stitch-design .chapter-illustrations:not(.hidden):not(.is-body-collapsed) {
  margin-bottom: 0.85rem;
  padding: 0.75rem;
  border: 1px solid var(--stitch-card-border);
  border-top: 3px solid var(--stitch-card-top);
  border-radius: 0.7rem;
  background: var(--stitch-card-bg);
  box-shadow: var(--stitch-card-shadow);
}

.reader-chapter-stitch-design .chapter-illustrations.is-body-collapsed,
.reader-chapter-stitch-design .chapter-illustrations.chapter-illustrations--toggle-docked.is-body-collapsed {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.reader-chapter-stitch-design .chapter-illustrations.is-body-collapsed:hover,
.reader-chapter-stitch-design .chapter-illustrations.chapter-illustrations--toggle-docked.is-body-collapsed:hover {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.reader-chapter-stitch-design .chapter-illustrations-toggle {
  color: hsl(var(--gold-dark));
}

/* Боковые панели */
body:has(.reader-chapter-stitch-design) .bible-reader-panel {
  --portal-right-drawer-bg: hsl(95 10% 95.5%);
  --portal-right-drawer-border: 1px solid hsl(95 10% 78% / 0.55);
}

body:has(.reader-chapter-stitch-design) .bible-reader-panel .panel-header {
  border-bottom: 1px solid hsl(var(--border) / 0.55);
  background: hsl(36 30% 94.5%);
}

body:has(.reader-chapter-stitch-design) .bible-reader-panel .panel-header h2 {
  color: hsl(var(--gold-dark));
  font-family: var(--font-display);
  font-weight: 600;
}

body:has(.reader-chapter-stitch-design) .bible-reader-panel .commentary-item,
body:has(.reader-chapter-stitch-design) .bible-reader-panel .dictionary-entry {
  margin-bottom: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--stitch-card-border);
  border-top: 3px solid var(--stitch-card-top);
  border-radius: 0.7rem;
  background: hsl(40 38% 95% / 0.65);
  box-shadow: var(--stitch-card-shadow);
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .comments-panel-toolbar {
  padding: 0.65rem 1rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border) / 0.45);
  background: hsl(36 30% 94.5% / 0.55);
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .comments-panel-sort {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.82rem;
  color: hsl(25 20% 28%);
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .comments-panel-sort span {
  font-weight: 600;
  letter-spacing: 0.04em;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .comments-panel-sort .bible-reader-select {
  min-width: 11rem;
  min-height: 2.15rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid hsl(var(--border) / 0.55);
  border-radius: 0.55rem;
  background: hsl(40 40% 99%);
  color: hsl(25 22% 16%);
  font-family: var(--font-display);
  font-size: 0.88rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .panel-body.reader-comments-list {
  flex: 1;
  overflow: auto;
  padding: 1rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .panel-body .loading {
  margin: 0;
  padding: 0.5rem 0;
  color: hsl(30 10% 52%);
  font-family: var(--font-display);
  font-size: 0.95rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .comments-panel-form {
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid hsl(var(--border) / 0.45);
  background: #F5EFEB;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem 0.85rem;
  margin: 0;
  padding: 1rem 1.1rem 0.95rem;
  border: 0;
  border-radius: 0.75rem;
  background: hsl(32 22% 91%);
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form__avatar {
  grid-row: 1 / span 2;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  background: hsl(var(--gold-dark));
  color: hsl(var(--ivory));
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form__fields {
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form label {
  display: block;
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form input,
body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form textarea {
  width: 100%;
  min-height: 2.45rem;
  margin: 0;
  padding: 0.65rem 0.8rem;
  border: 0;
  border-radius: 0.55rem;
  background: hsl(40 40% 99%);
  color: hsl(25 22% 16%);
  font-family: var(--font-display);
  font-size: 0.95rem;
  box-sizing: border-box;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form textarea {
  height: 2.7rem;
  min-height: 2.7rem;
  resize: vertical;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form input::placeholder,
body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form textarea::placeholder {
  color: hsl(30 8% 62%);
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form > button {
  grid-column: 2;
  justify-self: end;
  min-height: 2.2rem;
  margin-top: 0.15rem;
  padding: 0.45rem 1.15rem;
  border: 0;
  border-radius: 999px;
  background: hsl(var(--gold-dark));
  color: hsl(40 33% 97%);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-avatar {
  width: 2.25rem;
  height: 2.25rem;
  margin-top: 0.15rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: hsl(25 30% 18%);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-main {
  min-width: 0;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-bubble {
  padding: 1rem 1.15rem 1.05rem;
  border-radius: 1.1rem;
  background: #FDF2E9;
  box-shadow: none;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
  font-size: 0.72rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-author {
  color: hsl(25 30% 8%);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-date {
  color: hsl(30 10% 52%);
  font-family: var(--font-display);
  font-size: 0.75rem;
  white-space: nowrap;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-content {
  color: hsl(25 28% 8%);
  font-family: var(--font-display);
  font-size: 0.98rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1.15rem;
  margin-top: 0.5rem;
  padding-left: 0.2rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-actions .mini-select-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: hsl(25 20% 28%);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-actions .comment-like-btn {
  letter-spacing: 0.02em;
  text-transform: none;
  color: hsl(25 18% 36%);
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-replies {
  margin-top: 0.85rem;
  margin-left: 0;
  display: grid;
  gap: 0.85rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-replies .reader-comment-item {
  padding-left: 0.85rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-replies .reader-comment-avatar {
  width: 1.85rem;
  height: 1.85rem;
  font-size: 0.8rem;
}

body:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-replies .reader-comment-form {
  margin-top: 0.35rem;
}

body.dark:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .comments-panel-form {
  background: hsl(25 12% 14%);
}

body.dark:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-bubble {
  background: hsl(30 18% 18%);
}

body.dark:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form {
  background: hsl(25 12% 16%);
}

body.dark:has(.reader-chapter-stitch-design) #commentsPanel.comments-panel--stitch .reader-comment-form > button {
  color: hsl(25 20% 10%);
}

/* Оверлей аудио чтения главы */
body:has(.reader-chapter-stitch-design) .chapter-audio-overlay__sheet {
  border: 1px solid var(--stitch-card-border);
  border-top: 3px solid var(--stitch-card-top);
  background: var(--stitch-card-bg);
  box-shadow: var(--stitch-card-shadow), 0 1rem 2.5rem hsl(100 8% 20% / 0.12);
}

body:has(.reader-chapter-stitch-design) .chapter-audio-overlay__header h2 {
  color: hsl(var(--gold-dark));
  font-family: var(--font-display);
  font-weight: 600;
}

body:has(.reader-chapter-stitch-design) .chapter-audio-overlay__playpause {
  background: hsl(var(--gold-dark));
  color: hsl(40 33% 97%);
}

/* Диалог хронологии (моб.) */
body:has(.reader-chapter-stitch-design) .timeline-detail-dialog__sheet {
  border: 1px solid var(--stitch-card-border);
  background: var(--stitch-card-bg);
}

body:has(.reader-chapter-stitch-design) .timeline-detail-dialog__title {
  color: hsl(var(--gold-dark));
  font-family: var(--font-display);
}

/* Параллельные переводы */
.reader-chapter-stitch-design .verse-list.parallel-view .verse-item.parallel-row:hover,
.reader-chapter-stitch-design .verse-list.parallel-view .verse-item.parallel-row.verse-item--row-menu-active {
  background: var(--stitch-card-bg);
  box-shadow: var(--stitch-card-shadow);
}

/* Тёмная тема */
body.dark .reader-chapter-stitch-design {
  --stitch-card-bg: hsl(100 8% 16%);
  --stitch-card-border: hsl(var(--border) / 0.55);
  color: hsl(var(--foreground));
}

body.dark .reader-chapter-stitch-design .verse-list {
  color: hsl(38 18% 90%);
}

body.dark .reader-chapter-stitch-design .verse-search-form {
  background: hsl(100 8% 16% / 0.85);
}

body.dark .reader-chapter-stitch-design .verse-item:hover,
body.dark .reader-chapter-stitch-design .verse-item.verse-item--row-menu-active,
body.dark .reader-chapter-stitch-design .verse-item.is-target {
  background: hsl(100 8% 16%);
}

@media (max-width: 768px) {
  .reader-chapter-stitch-design > .reader-chapter-top-nav {
    margin-bottom: 1rem;
    padding-inline: max(0.85rem, env(safe-area-inset-left, 0px));
  }

  .reader-chapter-stitch-design .verses-section > .verses-section-toolbar {
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  }
}
