:root {
  --ink: #1c1a17;
  --muted: #5c564e;
  --paper: #f7f4ef;
  --panel: #ffffff;
  --line: #d8d0c4;
  --accent: #6b4f2a;
  --accent-soft: #efe6d6;
  --max: 720px;
  --wide: 1040px;
  --serif: "Source Serif 4", "Literata", "PT Serif", Georgia, serif;
  --sans: "Source Sans 3", "PT Sans", "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top, #fffdf9 0%, var(--paper) 55%, #efe8dc 100%);
  font-family: var(--sans);
  line-height: 1.65;
  min-height: 100vh;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: #4a3518;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: rgba(247, 244, 239, 0.92);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header__inner,
.site-footer__inner,
.wrap {
  width: min(100% - 2rem, var(--wide));
  margin-inline: auto;
}

/* При открытых комментариях — почти вся ширина экрана, прижато влево */
@media (min-width: 1040px) {
  .site-main:has(.article-with-comments.is-comments-open) .wrap {
    width: calc(100% - 2rem);
    max-width: none;
    margin-left: 1rem;
    margin-right: 1rem;
  }
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.9rem 0;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  align-items: center;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav a:hover,
.nav a.is-active {
  color: var(--ink);
}

/* Кнопка «Комментарии» в шапке — только на узких экранах и страницах статей */
.nav-comments {
  display: none;
}

@media (max-width: 1039px) {
  .nav-comments {
    display: inline;
    font-weight: 600;
    color: var(--accent);
  }
}

.site-main {
  padding: 2.5rem 0 4rem;
}

.hero {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}

.hero__title,
.page-title,
.article-body h2,
.article-body .block-heading {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.hero__title,
.page-title {
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  margin: 0 0 0.75rem;
}

.hero__lead,
.lede,
.muted {
  color: var(--muted);
}

.hero__image {
  margin: 1.5rem 0 0;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel);
}

.hero__image img {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
}

.section-title {
  font-family: var(--serif);
  font-size: 1.35rem;
  margin: 0 0 1rem;
}

.card-list {
  display: grid;
  gap: 1.25rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 1.25rem 1.4rem;
}

.card--article {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.card__meta {
  margin: 0;
}

.card__row {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

/* Квадрат по высоте примерно: заголовок + 2 строки описания */
.card__cover {
  --cover-size: calc(1.2rem * 1.3 + 0.35rem + 1em * 1.65 * 2);
  flex: 0 0 var(--cover-size);
  width: var(--cover-size);
  height: var(--cover-size);
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--accent-soft);
}

.card__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__body {
  min-width: 0;
  flex: 1;
}

.card h3 {
  font-family: var(--serif);
  font-size: 1.2rem;
  margin: 0 0 0.35rem;
  line-height: 1.3;
}

.card h3 a {
  color: var(--ink);
  text-decoration: none;
}

.card h3 a:hover {
  color: var(--accent);
}

.card__intro {
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

@media (max-width: 640px) {
  .card__cover {
    --cover-size: calc(1.1rem * 1.3 + 0.3rem + 1em * 1.55 * 2);
  }
}

.meta {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.article {
  width: min(100%, var(--max));
}

.article-with-comments {
  display: block;
}

@media (min-width: 1040px) {
  .article-with-comments {
    display: grid;
    grid-template-columns: minmax(0, var(--max)) minmax(240px, 280px);
    column-gap: 2rem;
    align-items: start;
    justify-content: start;
  }

  .article-with-comments .article {
    width: 100%;
  }

  /* Раскрытие: статья слева, комментарии забирают всё оставшееся место справа */
  .article-with-comments.is-comments-open {
    grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
    column-gap: 2.5rem;
  }

  .article-with-comments.is-comments-open .comments-panel {
    position: sticky;
    top: 5.5rem;
    max-height: calc(100vh - 6.5rem);
    width: 100%;
    min-width: 0;
  }

  .article-with-comments.is-comments-open .comments-panel__drawer {
    max-height: calc(100vh - 6.5rem);
    overflow: auto;
    width: 100%;
  }

  .article-with-comments.is-comments-open .comment-form,
  .article-with-comments.is-comments-open .comment-form--reply,
  .article-with-comments.is-comments-open .comment-textarea,
  .article-with-comments.is-comments-open .comment-form textarea {
    max-width: none;
    width: 100%;
  }
}

.article-body {
  font-family: var(--serif);
  font-size: 1.05rem;
}

.article-body .block-heading {
  font-size: 1.35rem;
  margin: 2rem 0 0.75rem;
}

.article-body .block-paragraph {
  margin: 0 0 1.1rem;
}

.article-body blockquote,
.article-body .block-quote {
  margin: 1.5rem 0;
  padding: 0.25rem 0 0.25rem 1.1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}

.figure {
  margin: 1.75rem 0;
}

.figure img {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
}

.figure figcaption,
.gallery-inline__title {
  margin-top: 0.5rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--muted);
}

.gallery-inline {
  margin: 2rem 0;
  padding: 1rem;
  background: var(--accent-soft);
  border: 1px solid var(--line);
}

.gallery-inline__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.gallery-folders,
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.folder-card,
.photo-card {
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
}

.folder-card a,
.photo-card {
  color: inherit;
  text-decoration: none;
  display: block;
}

.folder-card__body,
.photo-card figcaption {
  padding: 0.85rem 1rem 1rem;
}

.folder-card img,
.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--accent-soft);
}

.contact-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
}

.contact-list li {
  margin: 0 0 0.6rem;
}

.author-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.author-portrait {
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel);
}

.author-portrait img {
  display: block;
  width: 100%;
  height: auto;
}

.author-body p {
  margin: 0 0 1.1rem;
}

.author-body p:last-child {
  margin-bottom: 0;
}

/* Комментарии: на десктопе — колонка справа; на узких экранах — под статьёй */
.comments-panel {
  margin-top: 2.5rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--line);
  /* запас под липкую шапку при переходе по #comments */
  scroll-margin-top: 5.5rem;
}

.article[data-article-top] {
  scroll-margin-top: 5.5rem;
}

.comments-panel__collapse {
  display: none;
  width: 100%;
  margin-top: 1.5rem;
}

@media (max-width: 1039px) {
  /* На мобилках крестик в шапке панели не нужен — есть «Свернуть» внизу */
  .comments-panel__close {
    display: none;
  }

  .comments-panel.is-open .comments-panel__collapse {
    display: block;
  }

  .comments-panel__drawer {
    border: none;
    padding: 0;
    background: transparent;
  }

  .comments-panel__drawer-head {
    margin-bottom: 1rem;
  }
}

@media (min-width: 1040px) {
  .comments-panel {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    position: sticky;
    top: 5.5rem;
    max-height: calc(100vh - 6.5rem);
  }

  .comments-panel__collapse {
    display: none !important;
  }
}

.comments-panel__peek {
  display: block;
  width: 100%;
  margin: 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  background: var(--panel);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.comments-panel__peek:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 0 rgba(28, 26, 23, 0.04);
}

.comments-panel__peek-title {
  display: block;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.comments-panel__preview {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.comments-panel__preview-item {
  padding-top: 0.65rem;
  border-top: 1px solid var(--line);
}

.comments-panel__preview-item:first-child {
  padding-top: 0;
  border-top: none;
}

.comments-panel__preview-author {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.comments-panel__preview-text {
  display: block;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--ink);
}

.comments-panel__preview-text--muted,
.comments-panel__preview-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
  font-style: italic;
}

.comments-panel__peek-hint {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--accent);
}

.comments-panel.is-open .comments-panel__peek {
  display: none;
}

.comments-panel__drawer {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem 1.1rem 1.25rem;
}

.comments-panel__drawer-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.comments-panel__title {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  margin-right: auto;
}

.comments-panel__compose-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.comments-panel__compose-btn:hover,
.comments-panel__compose-btn[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.comments-panel__compose-icon {
  display: block;
}

.comments-panel__close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.2rem;
  flex-shrink: 0;
}

.comments-panel__close:hover {
  color: var(--ink);
}

.comments-panel__login {
  margin: 0 0 1rem;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}

.comment-form--reply {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.85rem 0 0;
  max-width: none;
  width: 100%;
  box-sizing: border-box;
}

.comment-form--reply .auth-label {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.comment-form--reply .comment-textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 16rem;
  font-size: 1.05rem;
  line-height: 1.55;
}

.comment-textarea,
.comment-form textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  resize: vertical;
}

.comment-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.comment-list--replies {
  margin-top: 0.85rem;
  padding-left: 0.85rem;
  border-left: 2px solid var(--line);
  gap: 0.85rem;
}

.comment__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.comment__author {
  color: var(--ink);
  font-weight: 600;
}

.comment__meta .comment-delete {
  display: inline-flex;
  margin-left: auto;
}

.comment__body {
  margin: 0;
  line-height: 1.5;
  font-size: 0.95rem;
}

.comment__body--deleted {
  color: var(--muted);
  font-style: italic;
}

.comment__actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  margin-top: 0.4rem;
}

/* details в flex по умолчанию сжимается по контенту — растягиваем на всю колонку */
.comment-reply,
.comment-edit {
  display: block;
  width: 100%;
  min-width: 0;
}

.comment-reply summary,
.comment-edit summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
  width: fit-content;
}

.comment-edit + .comment-reply {
  margin-top: 0.35rem;
}

.comment-form--edit {
  margin-top: 0.85rem;
}

.comment-edit-images {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.comment-edit-images__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.comment-edit-images__item {
  margin: 0;
}

.comment-edit-images__label {
  position: relative;
  display: block;
  cursor: pointer;
  line-height: 0;
}

.comment-edit-images__check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.comment-edit-images__thumb {
  width: 5.5rem;
  height: 5.5rem;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f6f4ef;
}

.comment-edit-images__mark {
  position: absolute;
  top: 0.2rem;
  right: 0.25rem;
  width: 1.35rem;
  height: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.85;
}

.comment-edit-images__check:checked + .comment-edit-images__thumb {
  opacity: 0.35;
}

.comment-edit-images__check:checked ~ .comment-edit-images__mark {
  background: #8b2e2e;
  opacity: 1;
}

.comment-edit-images__label:hover .comment-edit-images__mark {
  opacity: 1;
}

.comment-delete__btn {
  border: none;
  background: none;
  padding: 0 0.15rem;
  color: var(--muted);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
}

.comment-delete__btn:hover {
  color: #8b2e2e;
}

.comment-messages {
  list-style: none;
  padding: 0;
  margin: 0 0 0.85rem;
}

.comment-messages__item {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.comment-messages__item--success {
  color: #2d5a3d;
}

.comment-messages__item--error {
  color: #8b2e2e;
}

.comment-images-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.88rem;
}

.comment-images-field__label {
  color: var(--muted);
}

.comment-images-field input[type="file"] {
  font: inherit;
  font-size: 0.85rem;
  max-width: 100%;
}

.comment-images-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.comment-images-preview:empty {
  display: none;
}

.comment-images-preview__item {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f6f4ef;
}

.comment-images {
  list-style: none;
  padding: 0;
  margin: 0.55rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.comment-images__link {
  display: block;
  line-height: 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.comment-compose {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.comment-compose__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.comment-compose__cancel {
  border: none;
  background: none;
  padding: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.comment-compose__cancel:hover {
  color: var(--ink);
}

.comment-images__thumb {
  width: 5.5rem;
  height: 5.5rem;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f6f4ef;
}

.comment-images__thumb:hover {
  opacity: 0.9;
}

.comment-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  box-sizing: border-box;
  background: rgba(20, 18, 14, 0.78);
}

.comment-lightbox[hidden] {
  display: none;
}

html.is-lightbox-open,
html.is-lightbox-open body {
  overflow: hidden;
}

.comment-lightbox__img {
  display: block;
  max-width: min(92vw, 56rem);
  max-height: 88vh;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #111;
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.35);
}

.comment-lightbox__close {
  position: fixed;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 2001;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.search-form input[type="text"] {
  flex: 1 1 220px;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--panel);
  font: inherit;
}

.search-form button,
.button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0.65rem 1rem;
  font: inherit;
  cursor: pointer;
}

.search-form button:hover,
.button:hover {
  background: #4a3518;
  border-color: #4a3518;
}

a.button {
  display: inline-block;
  text-decoration: none;
}

.nav-user {
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-box {
  max-width: 28rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.25rem;
}

.auth-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
}

.auth-label input {
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--panel);
  font: inherit;
}

.auth-error {
  color: #8b2e2e;
  font-size: 0.85rem;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty {
  color: var(--muted);
  font-style: italic;
}

/* Научные сноски */
.footnote-ref {
  font-family: var(--sans);
  font-size: 0.75em;
  font-weight: 600;
  line-height: 1;
  margin-left: 0.1em;
  text-decoration: none;
  vertical-align: super;
}

.footnotes {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
}

.footnotes ol {
  padding-left: 1.4rem;
  margin: 0.75rem 0 0;
}

.footnotes li {
  margin: 0 0 0.55rem;
  line-height: 1.45;
}

.footnotes li:target {
  background: var(--accent-soft);
  outline: 1px solid var(--line);
  padding: 0.15rem 0.35rem;
}

.footnote-back {
  margin-left: 0.35rem;
  text-decoration: none;
  font-size: 0.85em;
}

@media (max-width: 640px) {
  html {
    font-size: 17px;
  }

  .site-header__inner {
    align-items: flex-start;
  }
}
