/*
 * Сторис (js/stories.js): лента карточек на Главной и просмотр на весь экран.
 * Замечание Тима №10 (03.10): «прямоугольные карточки с превью, текст снизу,
 * обводка просмотрено/нет; на весь экран с кнопками, листание, удержание,
 * как в нормальных приложениях».
 * Движение только transform/opacity; при «меньше движения» stories.js сам
 * меняет кадры прозрачностью, здесь гасим нажатия и мерцание.
 */

/* ── Лента ─────────────────────────────────────────────────────────────
   Карточка 3:4, 92×122, радиус 16. Лента выходит к краям экрана (поля 16
   внутри неё), чтобы край следующей карточки был виден: понятно, что листается.
   Отступ 4 px сверху и снизу — место под обводку. */
body.n1 .nst-strip {
  display: flex;
  gap: 10px;
  margin: -4px -16px;
  padding: 4px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding: 0 16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
body.n1 .nst-strip::-webkit-scrollbar { display: none; }

body.n1 .nst-card {
  position: relative;
  flex: 0 0 auto;
  width: 92px;
  height: 122px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  background: var(--n1-card2);
  color: #fff;
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* не просмотрена: салатовая обводка 2 px с зазором 2 px цвета фона */
  box-shadow: 0 0 0 2px var(--n1-bg), 0 0 0 4px var(--n1-lime);
}
/* просмотрена: тонкая серая */
body.n1 .nst-card--seen { box-shadow: 0 0 0 1px #5c5c5c; }
body.n1 .nst-card:focus-visible { outline: 2px solid var(--n1-lime); outline-offset: 5px; }

body.n1 .nst-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 0;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
/* затемнение снизу под подписью. Пока у истории нет своей обложки, обложка:
   сам слайд, а на слайдах Тима внизу свой текст. Нижние 30% карточки поэтому
   чисто чёрные: текст и плашки слайда не просвечивают сквозь подпись и не
   торчат под ней (на 320 были видны верхушки букв заголовка слайда). */
body.n1 .nst-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 70%;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, .62) 30%, #000 57%);
  pointer-events: none;
}
/* своя обложка истории (картинка 2:3 или 3:4, у обложек Тима внизу тёмное
   поле под подпись; класс ставит stories.js по размеру картинки): затемнение
   только под подписью, 3D сверху видна целиком */
body.n1 .nst-card--art::after {
  height: 52%;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, .55) 45%, rgba(0, 0, 0, .82) 100%);
}
body.n1 .nst-cap {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 1;
  font: 600 13px/16px var(--n1-font);
  letter-spacing: -.08px;
  color: #fff;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow-wrap: break-word;
}
body.n1 .nst-card--seen .nst-cap { color: var(--n1-grey); }
/* у истории есть ролик */
body.n1 .nst-play {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  width: 20px;
  height: 20px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.n1 .nst-play svg { margin-left: 1px; }
/* загрузка, пока списка ещё нет */
body.n1 .nst-card--sk {
  box-shadow: none;
  cursor: default;
  background: linear-gradient(90deg, #363636 0%, #414141 45%, #363636 90%) 0 0 / 220% 100%;
  animation: n1-sk 1.4s linear infinite;
}
body.n1 .nst-card--sk::after { display: none; }

@media (max-width: 340px) {
  body.n1 .nst-card { width: 84px; height: 112px; }
  body.n1 .nst-cap { font-size: 12px; line-height: 15px; }
}

/* ── Просмотр на весь экран ───────────────────────────────────────────
   Сцена (.nst-stage) — то, что раскрывается из карточки и уходит в неё,
   и то, что ведёт палец при свайпе вниз. Внутри две грани куба. Кадр 9:16
   (.nst-box) стоит по размерам из stories.js (--nst-*). */
body.n1 .nst-viewer {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: none;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
body.n1 .nst-viewer.open { display: block; }
/* Тост поверх открытой истории встаёт ПОД её шапку (полосы, название,
   крестик), а не на неё: иначе он закрывал крестик и заголовок. Высоту
   шапки пишет stories.js (layout, --nst-toast-top на <html>). */
:root:has(> body.n1 .nst-viewer.open) #__ios_notif_root {
  padding-top: var(--nst-toast-top, calc(env(safe-area-inset-top, 0px) + 68px)) !important;
}
body.n1 .nst-bd { position: absolute; inset: 0; background: #000; }
body.n1 .nst-stage { position: absolute; inset: 0; perspective: 1100px; }
body.n1 .nst-face {
  position: absolute;
  inset: 0;
  background: #000;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform-origin: 50% 50%;
}
body.n1 .nst-face[hidden] { display: none; }
/* пока сцена летит или её тянут вниз, вокруг кадра виден экран под ним */
body.n1 .nst-fly .nst-face,
body.n1 .nst-drag .nst-face { background: transparent; }
body.n1 .nst-fly .nst-turn,
body.n1 .nst-drag .nst-turn { display: none; }

body.n1 .nst-box {
  position: absolute;
  left: var(--nst-left, 0px);
  top: var(--nst-top, 0px);
  width: var(--nst-w, 100%);
  height: var(--nst-h, 100%);
  overflow: hidden;
  border-radius: 12px;
  background: #161616;
  /* скругление обрезает и детей при переносе слоя (Safari) */
  -webkit-mask-image: -webkit-radial-gradient(white, black);
}
body.n1 .nst-img,
body.n1 .nst-vid,
body.n1 .nst-blur {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
body.n1 .nst-img[hidden],
body.n1 .nst-vid[hidden] { display: none; }
body.n1 .nst-blur { display: none; filter: blur(28px) brightness(.5); transform: scale(1.15); }
/* картинка не 9:16: целиком, на размытом фоне себя же */
body.n1 .nst-contain .nst-blur { display: block; }
body.n1 .nst-contain .nst-img,
body.n1 .nst-contain .nst-vid { object-fit: contain; }

body.n1 .nst-shade-top {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: calc(112px + var(--nst-ct, 0px));
  background: linear-gradient(180deg, rgba(0, 0, 0, .45) 0, rgba(0, 0, 0, .18) 60%, rgba(0, 0, 0, 0) 100%);
  pointer-events: none;
}
/* кнопка поверх кадра (экран 9:16 и ниже): затемнение под ней */
body.n1 .nst-shade-bot {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 168px;
  background: linear-gradient(0deg, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0));
  pointer-events: none;
}
body.n1 .nst-viewer:not(.nst-tall) .nst-has-cta .nst-shade-bot { display: block; }

body.n1 .nst-chrome {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(8px + var(--nst-ct, 0px)) 8px 0;
  transition: opacity .2s ease;
}
body.n1 .nst-bars { display: flex; gap: 4px; padding: 0 2px; }
body.n1 .nst-bar {
  flex: 1;
  height: 2px;
  border-radius: 1px;
  background: rgba(255, 255, 255, .35);
  overflow: hidden;
}
body.n1 .nst-fill {
  height: 100%;
  background: #fff;
  transform-origin: 0 50%;
  transform: scaleX(0);
}
body.n1 .nst-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  margin-top: 6px;
  padding-left: 6px;
}
body.n1 .nst-ava {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 33%;
  background: var(--n1-card2);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .25);
}
body.n1 .nst-ava[hidden] { display: none; }
body.n1 .nst-title {
  flex: 1;
  min-width: 0;
  font: 600 15px/20px var(--n1-font);
  letter-spacing: -.23px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .45);
}
body.n1 .nst-ib {
  flex: none;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, .45));
}
body.n1 .nst-ib[hidden] { display: none; }

/* кнопка действия: под кадром на высоком телефоне, поверх низа на остальных */
body.n1 .nst-foot {
  position: absolute;
  left: calc(var(--nst-left, 0px) + 16px);
  width: calc(var(--nst-w, 100%) - 32px);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transition: opacity .2s ease;
}
body.n1 .nst-tall .nst-foot { top: var(--nst-ft, auto); bottom: auto; }
body.n1 .nst-foot[hidden] { display: none; }
body.n1 .nst-cta {
  width: 100%;
  height: 56px;
  margin: 0;
  padding: 0 20px;
  border: 0;
  border-radius: 28px;
  background: var(--n1-lime);
  color: var(--n1-on-lime);
  font: 600 17px/22px var(--n1-font);
  letter-spacing: -.4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
body.n1 .nst-cta-t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
body.n1 .nst-cta svg { flex: none; }

/* удержание: верх и низ прячутся, остаётся кадр */
body.n1 .nst-hold .nst-chrome,
body.n1 .nst-hold .nst-foot,
body.n1 .nst-hold .nst-shade-top,
body.n1 .nst-hold .nst-shade-bot { opacity: 0; }
body.n1 .nst-shade-top,
body.n1 .nst-shade-bot { transition: opacity .2s ease; }
/* пока кадр раскрывается из карточки, кнопка внизу не мельтешит */
body.n1 .nst-fly .nst-foot { opacity: 0; transition: none; }

/* грань, уходящая за угол куба, темнеет */
body.n1 .nst-turn {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}

/* ждём кадр: крутилка по центру */
body.n1 .nst-spin {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  animation: nst-spin .8s linear infinite;
}
body.n1 .nst-loading .nst-spin { opacity: 1; }
@keyframes nst-spin { to { transform: rotate(360deg); } }

/* кнопки «назад/дальше» для VoiceOver и клавиатуры, глазами не видны */
body.n1 .nst-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  body.n1 .nst-card--sk { animation: none; }
  body.n1 .nst-spin { animation: none; border-color: rgba(255, 255, 255, .5); }
}
