/* Сообщество / explore — masonry
 * Тема: html[data-theme] (theme-init.js / theme.js), не body/.page-community. */
body.page-community {
  background-color: var(--bg);
  color: var(--text);
}

.page-community .test3-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 12px 48px;
  box-sizing: border-box;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.page-community .test3-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 14px;
  margin-bottom: 8px;
}

.page-community .test3-toolbar-intro {
  flex: 1 1 220px;
  min-width: 0;
  max-width: 42rem;
}

.page-community .test3-lede {
  margin: 6px 0 0;
  font-size: 0.92rem;
  line-height: 1.45;
  font-weight: 400;
  color: var(--text-muted);
}

.page-community .test3-toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  justify-content: flex-end;
  flex-shrink: 0;
  padding-top: 2px;
}

.page-community .test3-sort-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 0;
  max-width: 100%;
}

.page-community .test3-sort-label {
  color: inherit;
  opacity: 0.72;
  white-space: nowrap;
}

.page-community .test3-sort-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.06));
  color: inherit;
  padding: 8px 32px 8px 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.page-community .test3-sort-select:hover {
  opacity: 0.95;
}

.page-community .test3-sort-select:focus {
  outline: 2px solid var(--accent, #0066ff);
  outline-offset: 2px;
}

html[data-theme='dark'] .page-community .test3-sort-select {
  background-color: var(--td-surface-2);
  color: var(--text);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a1a1aa' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

@media (max-width: 640px) {
  .page-community .test3-main {
    overflow-x: hidden;
  }
  .page-community .test3-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .page-community .test3-toolbar-intro {
    flex: 0 0 auto;
    max-width: none;
  }
  .page-community .test3-toolbar-controls {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    justify-content: space-between;
  }
  .page-community .test3-tabs {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 3px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .page-community .test3-tabs::-webkit-scrollbar {
    display: none;
  }
  .page-community .test3-tab {
    padding: 7px 11px;
    font-size: 0.8125rem;
    flex-shrink: 0;
  }
  .page-community .test3-sort-label {
    display: none;
  }
  .page-community .test3-sort-field {
    flex: 0 0 auto;
    justify-content: flex-end;
  }
  .page-community .test3-sort-select {
    flex-shrink: 0;
    max-width: none;
    min-width: 0;
    padding: 7px 28px 7px 11px;
    font-size: 0.8125rem;
    background-position: right 10px center;
  }
  html[data-theme='dark'] .page-community .test3-sort-select {
    background-position: right 10px center;
  }
}

.page-community .test3-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--text);
}

.page-community .test3-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.page-community .test3-tab {
  border: none;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.06));
  color: inherit;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.page-community .test3-tab:hover {
  opacity: 0.9;
}

.page-community .test3-tab--active {
  background: var(--accent, #0066ff);
  color: #fff;
}

/*
 * JS masonry (shortest column): плотная «рваная» сетка как у Midjourney;
 * новинки уходят в колонку с меньшей высотой — не в один длинный левый столбец.
 */
.page-community .test3-masonry {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 4px;
  /* Не даём браузеру «якорить» скролл при перестановке карточек в DOM (конфликт с нашим scrollBy). */
  overflow-anchor: none;
}

.page-community .test3-masonry-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-community .test3-masonry > .test3-empty {
  flex: 1 1 100%;
  width: 100%;
  margin: 0;
}

.page-community .test3-masonry-col .test3-card {
  margin-bottom: 0;
}

.page-community .test3-card {
  break-inside: avoid;
  margin-bottom: 4px;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.04));
}

.page-community .test3-card-mod-remove {
  position: absolute;
  top: 6px;
  left: 6px;
  right: auto;
  z-index: 4;
  width: 30px;
  height: 30px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 6px;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.page-community .test3-card-mod-remove:hover,
.page-community .test3-card-mod-remove:focus-visible {
  background: rgba(180, 40, 40, 0.92);
  outline: none;
}

.page-community .test3-card img,
.page-community .test3-card video {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}

.page-community .test3-card img {
  background: var(--td-surface-2, rgba(0, 0, 0, 0.06));
}

/* Плейсхолдер до подстановки src (ленивая подгрузка в community.js) */
.page-community .test3-card img[data-nm-lazy-src],
.page-community .test3-card video[data-nm-lazy-src] {
  min-height: 120px;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.08));
}

.page-community .test3-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65) 0%, transparent 55%);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.page-community .test3-card:hover .test3-card-overlay,
.page-community .test3-card:focus-within .test3-card-overlay {
  opacity: 1;
}

.page-community .test3-card-meta {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.page-community .test3-card:hover .test3-card-meta,
.page-community .test3-card:focus-within .test3-card-meta {
  opacity: 1;
}

.page-community .test3-card-author {
  font-size: 0.75rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-community .test3-card-model {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  max-width: 35%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.page-community .test3-card-like {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.2;
}

.page-community .test3-card-like:hover {
  background: rgba(0, 0, 0, 0.72);
}

.page-community .test3-card-like--on .test3-like-icon {
  color: #ff4d6d;
}

.page-community .test3-like-icon {
  font-size: 0.85rem;
  line-height: 1;
}

.page-community .test3-sentinel {
  height: 4px;
  margin-top: 8px;
}

.page-community .test3-empty,
.page-community .test3-error {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

/* Без отступов, пока пусто — иначе огромная щель до masonry */
.page-community .test3-status {
  margin: 0;
  padding: 0;
  min-height: 0;
  line-height: 1.35;
}

.page-community .test3-status:not(:empty) {
  text-align: center;
  padding: 6px 8px 10px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Modal — две колонки как в Midjourney explore */
.page-community .test3-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-top: max(12px, env(safe-area-inset-top));
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: manipulation;
}

.page-community .test3-modal[hidden] {
  display: none !important;
}

.page-community .test3-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.page-community .test3-modal-shell {
  position: relative;
  width: 100%;
  max-width: min(960px, 100%);
  max-height: min(92vh, 720px, calc(100dvh - 24px));
  background: var(--td-surface, #ffffff);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html[data-theme='dark'] .page-community .test3-modal-shell {
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.page-community .test3-modal-body {
  display: grid;
  grid-template-columns: 1fr minmax(min(260px, 100%), 38%);
  gap: 0;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

@media (max-width: 720px) {
  .page-community .test3-modal-shell {
    max-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
  }
  .page-community .test3-modal-body {
    grid-template-columns: 1fr;
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .page-community .test3-modal-media-col {
    flex: 0 0 auto;
    min-height: 0;
    max-height: min(48vh, 50dvh, 360px);
    overflow: hidden;
    align-self: stretch;
  }
  .page-community .test3-modal-media-el,
  .page-community .test3-modal-media-col video.test3-modal-media-el {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: min(48vh, 50dvh, 360px);
    object-fit: contain;
    vertical-align: middle;
  }
  .page-community .test3-modal-media-col .test3-modal-img-hit {
    max-height: min(48vh, 50dvh, 360px);
  }
  .page-community .test3-modal-media-col .test3-modal-img-hit img {
    max-height: min(48vh, 50dvh, 360px);
  }

  /* Кнопка «×»: не обрезать (отрицательный margin + overflow родителя на мобиле) */
  .page-community .test3-modal-side {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-top: 14px;
  }
  .page-community .test3-modal-side-inner {
    padding-top: 2px;
  }
  .page-community .test3-modal-close-row {
    min-height: 44px;
  }
}

.page-community .test3-modal-media-col {
  background: #0a0a0b;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.page-community .test3-modal-media-el {
  display: block;
  max-width: 100%;
  max-height: min(72vh, 640px);
  width: auto;
  height: auto;
  object-fit: contain;
}

.page-community .test3-modal-media-col video.test3-modal-media-el {
  width: 100%;
  max-width: 100%;
  max-height: min(72vh, 640px);
  height: auto;
  object-fit: contain;
}

.page-community .test3-modal-side {
  padding: 12px 18px 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
}

.page-community .test3-modal-side-inner {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 4px;
}

/* Закрытие в панели справа / снизу — не перекрывает нативные кнопки видео (полноэкранный режим и т.д.) */
.page-community .test3-modal-close-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
  min-height: 40px;
  margin: 0;
}

.page-community .test3-modal-close {
  position: relative;
  z-index: 1;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.08));
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-community .test3-modal-close:hover {
  background: var(--td-surface-3, rgba(0, 0, 0, 0.12));
}

html[data-theme='dark'] .page-community .test3-modal-close {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

html[data-theme='dark'] .page-community .test3-modal-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.page-community .test3-modal-side-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.page-community .test3-modal-author-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.page-community .test3-modal-author {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.page-community .test3-modal-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.page-community .test3-like-btn--header {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.06));
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.page-community .test3-like-btn--header:hover {
  opacity: 0.92;
}

html[data-theme='dark'] .page-community .test3-like-btn--header {
  background: var(--td-surface-2);
  border-color: var(--border);
  color: var(--text);
}

.page-community .test3-like-btn--on {
  border-color: rgba(255, 77, 109, 0.45);
}

.page-community .test3-like-btn--on .test3-like-icon {
  color: #ff4d6d;
}

.page-community .test3-modal-model {
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0;
  color: var(--accent, #0066ff);
}

.page-community .test3-modal-prompt {
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  max-height: 28vh;
  overflow-y: auto;
  color: var(--text);
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.page-community .test3-modal-thumb-wrap {
  border-radius: 8px;
  overflow: hidden;
  max-width: 96px;
  border: 1px solid var(--border);
}

.page-community .test3-modal-thumb {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}

.page-community .test3-modal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.page-community .test3-chip {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--td-surface-2, rgba(0, 0, 0, 0.06));
  color: var(--text-secondary);
  font-weight: 500;
}

.page-community .test3-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  padding-top: 12px;
  margin-top: 0;
  border-top: 1px solid var(--border);
}

.page-community .test3-btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.page-community .test3-btn--block {
  width: 100%;
  justify-content: center;
}

.page-community .test3-btn--primary {
  background: var(--accent, #0066ff);
  color: #fff;
}

.page-community .test3-btn--primary:hover:not(:disabled) {
  background: var(--accent-hover, #0052cc);
}

.page-community .test3-btn--primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page-community .test3-btn--ghost {
  background: var(--td-surface-2, rgba(0, 0, 0, 0.08));
  color: inherit;
}

/* Блокировка «резинового» скролла страницы под модалкой */
body.test3-modal-scroll-lock {
  overscroll-behavior: none;
}

/* Область нажатия: открыть фото на весь экран */
.page-community .test3-modal-img-hit {
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.page-community .test3-modal-img-hit:focus {
  outline: 2px solid var(--accent, #0066ff);
  outline-offset: 2px;
}

.page-community .test3-modal-media-col > .test3-modal-img-hit {
  max-height: min(72vh, 640px);
  box-sizing: border-box;
}

/* Как у video.test3-modal-media-el: явный потолок по высоте, без «раздувания» грида */
.page-community .test3-modal-img-hit img {
  max-width: 100%;
  max-height: min(72vh, 640px);
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

/* Fallback, если Fullscreen API недоступен (часть мобильных Safari) */
.test3-fs-overlay {
  position: fixed;
  inset: 0;
  z-index: 10060;
  /* Единый «кинотеатральный» фон в светлой и тёмной теме */
  background: var(--test3-fs-bg, #0a0a0c);
  color-scheme: dark;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
  overscroll-behavior: contain;
  touch-action: manipulation;
}

html[data-theme='dark'] .test3-fs-overlay {
  --test3-fs-bg: #000000;
}

.test3-fs-overlay[hidden] {
  display: none !important;
}

.test3-fs-overlay-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.test3-fs-overlay-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgba(20, 20, 24, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.test3-fs-overlay-close:hover {
  background: rgba(36, 36, 42, 0.72);
  border-color: rgba(255, 255, 255, 0.3);
}
