/**
 * Новости: блок внизу страниц, список-кладка, страница новости.
 *
 * Эталон — news-demo (news-tz-site.md, раздел 8). Цвета эталона вынесены
 * в токены --nw-*, тема берётся с сайта: тёмная по умолчанию, светлая по
 * системной настройке и по явному выбору data-theme на <html>.
 */

.nw-scope {
  --nw-bg: #0f1224;
  --nw-card: #171b33;
  --nw-ink: #eef0fb;
  --nw-muted: #9aa0c3;
  --nw-line: #2a2f52;
  --nw-accent: #7f90ff;
  --nw-soft: #222a55;
  --nw-deep: #b7c1ff;
  --nw-shadow: 0 10px 30px rgba(0, 0, 0, .28);
  --nw-shadow-hover: 0 18px 40px rgba(0, 0, 0, .4);

  background: var(--nw-bg);
  color: var(--nw-ink);
  font-family: var(--sans, "Onest", -apple-system, "Segoe UI", Roboto, Arial, sans-serif);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .nw-scope {
    --nw-bg: #f4f5fb;
    --nw-card: #ffffff;
    --nw-ink: #14172b;
    --nw-muted: #6b7090;
    --nw-line: #e3e5f1;
    --nw-accent: #5468e6;
    --nw-soft: #e9ecfd;
    --nw-deep: #3a4cc4;
    --nw-shadow: 0 10px 30px rgba(36, 44, 110, .07);
    --nw-shadow-hover: 0 18px 40px rgba(36, 44, 110, .12);
  }
}

:root[data-theme="light"] .nw-scope {
  --nw-bg: #f4f5fb;
  --nw-card: #ffffff;
  --nw-ink: #14172b;
  --nw-muted: #6b7090;
  --nw-line: #e3e5f1;
  --nw-accent: #5468e6;
  --nw-soft: #e9ecfd;
  --nw-deep: #3a4cc4;
  --nw-shadow: 0 10px 30px rgba(36, 44, 110, .07);
  --nw-shadow-hover: 0 18px 40px rgba(36, 44, 110, .12);
}

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

.nw-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--pad, 16px);
}

.nw-wrap--page {
  max-width: 1000px;
}

/* ============================ Блок ============================ */

.nw-block {
  padding: 56px 0;
}

.nw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.nw-head h2 {
  margin: 0;
  font-size: 36px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -.02em;
}

.nw-all {
  display: inline-block;
  font-weight: 600;
  font-size: 16px;
  color: var(--nw-deep);
  background: var(--nw-soft);
  text-decoration: none;
  padding: 12px 22px;
  border-radius: 99px;
  white-space: nowrap;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  transition: background .2s, color .2s;
}

.nw-all:hover {
  background: var(--nw-accent);
  color: #fff;
}

.nw-all:focus-visible,
.nw-card:focus-visible,
.nw-pager:focus-visible,
.nw-pagernav a:focus-visible,
.nw-nav:focus-visible,
.nw-carousel:focus-visible {
  outline: 3px solid var(--nw-accent);
  outline-offset: 3px;
}

/* Карточки не растягиваются по высоте: align-items: start. */
.nw-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}

@media (min-width: 1024px) {
  .nw-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ============================ Карточка ============================ */

.nw-card {
  display: flex;
  flex-direction: column;
  background: var(--nw-card);
  border: 1.5px solid var(--nw-line);
  border-radius: 22px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--nw-shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}

.nw-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--nw-shadow-hover);
}

.nw-media {
  background: var(--nw-soft);
  overflow: hidden;
}

.nw-media picture {
  display: block;
  width: 100%;
  height: 100%;
}

.nw-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nw-media[data-ratio="1:1"] { aspect-ratio: 1 / 1; }
.nw-media[data-ratio="3:4"] { aspect-ratio: 3 / 4; }
.nw-media[data-ratio="4:3"] { aspect-ratio: 4 / 3; }

.nw-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.nw-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.nw-desc {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--nw-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.nw-date {
  margin-top: auto;
  font-size: 13px;
  color: var(--nw-muted);
}

/* ============================ Страницы ============================ */

.nw-page {
  padding: 40px 0 80px;
}

.nw-crumbs {
  font-size: 14px;
  color: var(--nw-muted);
  margin-bottom: 14px;
}

.nw-crumbs a {
  color: var(--nw-muted);
}

.nw-top {
  margin-bottom: 32px;
}

.nw-h1 {
  margin: 0;
  font-size: 44px;
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -.03em;
}

.nw-h1--page {
  font-size: 40px;
  line-height: 1.1;
  margin-bottom: 12px;
}

@media (max-width: 600px) {
  .nw-h1,
  .nw-h1--page {
    font-size: 30px;
  }

  .nw-head h2 {
    font-size: 28px;
  }
}

.nw-preview {
  margin: 0 0 18px;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--nw-soft);
  color: var(--nw-deep);
  font-size: 14px;
}

/* Кладка: запасной вариант на CSS-колонках, JS заменяет его колонками-flex. */
.nw-masonry {
  column-width: 260px;
  column-gap: 20px;
}

.nw-masonry > .nw-card {
  break-inside: avoid;
  margin-bottom: 20px;
}

.nw-masonry.is-js {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  column-width: auto;
}

.nw-masonry.is-js .nw-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nw-masonry.is-js > .nw-card {
  margin-bottom: 0;
}

.nw-pages {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 36px;
  flex-wrap: wrap;
}

.nw-pager {
  font-weight: 600;
  color: var(--nw-deep);
  background: var(--nw-soft);
  text-decoration: none;
  padding: 12px 22px;
  border-radius: 99px;
}

/* ============================ Страница новости ============================ */

.nw-meta {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--nw-muted);
}

.nw-layout {
  display: grid;
  gap: 24px;
  --nw-media-w: 440px;
}

.nw-layout[data-ratio="3:4"] { --nw-media-w: 380px; }
.nw-layout[data-ratio="4:3"] { --nw-media-w: 500px; }

@media (min-width: 860px) {
  .nw-layout {
    grid-template-columns: var(--nw-media-w) minmax(0, 1fr);
    gap: 40px;
    align-items: start;
  }
}

.nw-carousel {
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  overflow: hidden;
  background: var(--nw-soft);
  border: 1.5px solid var(--nw-line);
}

.nw-carousel[data-ratio="3:4"] { aspect-ratio: 3 / 4; }
.nw-carousel[data-ratio="4:3"] { aspect-ratio: 4 / 3; }

.nw-track {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  scroll-behavior: smooth;
}

.nw-track::-webkit-scrollbar {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .nw-track {
    scroll-behavior: auto;
  }

  .nw-card {
    transition: none;
  }
}

.nw-slide {
  flex: 0 0 100%;
  height: 100%;
  margin: 0;
  scroll-snap-align: center;
}

.nw-slide picture {
  display: block;
  width: 100%;
  height: 100%;
}

.nw-slide img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nw-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 23, 43, .55);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.nw-nav--prev { left: 12px; }
.nw-nav--next { right: 12px; }

.nw-count {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 4px 12px;
  border-radius: 99px;
  background: rgba(20, 23, 43, .6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.nw-text {
  font-size: 18px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.nw-text p {
  margin: 0 0 16px;
}

.nw-text h2 {
  margin: 24px 0 12px;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 700;
}

.nw-text strong {
  font-weight: 700;
}

.nw-text a {
  color: var(--nw-deep);
  text-decoration: underline;
}

.nw-text a:hover {
  color: var(--nw-accent);
}

.nw-text mark {
  background: var(--nw-soft);
  color: inherit;
  padding: 0 .15em;
  border-radius: 4px;
}

.nw-pagernav {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1.5px solid var(--nw-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.nw-pagernav a {
  font-weight: 600;
  color: var(--nw-deep);
  text-decoration: none;
  background: var(--nw-soft);
  padding: 10px 18px;
  border-radius: 99px;
}

.nw-pagernav a:hover {
  background: var(--nw-accent);
  color: #fff;
}
