/* Лента нарезок — Reels/TikTok-паттерн, адаптив под мобильный Telegram WebView */
:root {
  --bg: #0d0d12;
  --fg: #f2f2f5;
  --muted: #9a9aa8;
  --accent: #e11d2e; /* алая — единый красный стиль кнопок (без зелёной) */
  --danger: #a4121d; /* тёмно-красный */
  --glass: rgba(18, 18, 26, 0.72);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* [hidden] должен побеждать авторский display (иначе оверлеи видны всегда) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* ---- Лента ---- */
#feed {
  height: 100vh;
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth; /* плавный snap с инерцией */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 6px;
}
#feed::-webkit-scrollbar { display: none; }

.card {
  position: relative;
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  /* мягкие скругления/тени карточек (Instagram-уровень), палитра прежняя */
  border-radius: 16px;
  margin-bottom: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}
.card video {
  width: 100%;
  height: 100%;
  object-fit: cover; /* фулскрин-кроп как в Reels/TikTok */
  background: #000;
}
.card .video-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  padding: 24px;
  z-index: 2;
}
.card .video-error .video-retry {
  width: auto;
  margin-top: 10px;
  padding: 12px 22px;
}

/* ---- Скелетон до постера/первого кадра: тёмное стекло с мягким шиммером;
   карточка всегда 100dvh — геометрия зарезервирована, прыжков layout нет ---- */
.card-skeleton {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(150deg, #14141d 0%, #1b1b27 55%, #14141d 100%);
  overflow: hidden;
  transition: opacity 0.3s ease;
}
.card-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.06) 50%, transparent 65%);
  animation: skeleton-sheen 1.6s ease-in-out infinite;
}
.card-skeleton.fade-out { opacity: 0; }
@keyframes skeleton-sheen {
  0% { transform: translateX(-70%); }
  100% { transform: translateX(70%); }
}

/* ---- Кроссфейд постер -> видео (opacity 300ms по canplay, см. wirePosterFade) ---- */
.poster-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.poster-layer.ready { opacity: 1; }
.poster-layer.fade-out { opacity: 0; }

/* ---- Индикатор буферизации поверх видео: тонкое стеклянное кольцо
   в стиле пилюли звука, fade in/out, авто-скрытие (см. wireBuffering) ---- */
.buffer-indicator {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}
.buffer-spin {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.88);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: buffer-rotate 0.9s linear infinite;
}
@keyframes buffer-rotate { to { transform: rotate(360deg); } }

/* ---- Верхний бар ---- */
/* ---- Прогресс как stories (B3): тонкие полоски сверху — просмотрено/осталось ---- */
.stories {
  position: fixed;
  top: calc(6px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 3px;
  height: 3px;
  z-index: 21;
  pointer-events: none;
}
.story-seg {
  flex: 1 1 0;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}
.story-seg.done { background: rgba(255, 255, 255, 0.82); }
.story-seg.current b {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
}

#topbar {
  position: fixed;
  top: calc(20px + var(--safe-top));
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}
.chip {
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}
.chip-ghost { color: var(--muted); font-weight: 500; }

/* ---- Нижняя панель действий: крупные кнопки ✅/🗑 над прогресс-баром ----
 * Бар — в самом низу (над safe-area), кнопки строго выше него, без перекрытия. */
#controls {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(24px + var(--safe-bottom));
  display: flex;
  gap: 22px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  z-index: 20;
}
.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.action-label {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
/* Крупная круглая кнопка действия: тап-зона 64px (большой палец) */
.btn-action {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.38);
  transition: transform 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
}
.btn-action .icon { font-size: 30px; line-height: 1; }
.btn-action:active { transform: scale(0.9); }
/* «вдавленная» кнопка 100ms при тапе (см. animateActionButton) */
.btn-action.pressed, .btn.pressed {
  transform: scale(0.86);
  transition: transform 0.1s ease;
}
/* Всплывающая реакция тапа ✅/🗑: эмодзи-частица всплывает и растворяется */
.tap-burst {
  position: fixed;
  z-index: 80;
  font-size: 34px;
  line-height: 1;
  pointer-events: none;
  transform: translate(-50%, 0) scale(0.5);
  opacity: 0;
  animation: tap-burst 0.65s ease-out forwards;
}
@keyframes tap-burst {
  0% { opacity: 0; transform: translate(-50%, 4px) scale(0.5); }
  22% { opacity: 1; transform: translate(-50%, -12px) scale(1.18); }
  100% { opacity: 0; transform: translate(-50%, -54px) scale(0.85); }
}
.action-like { background: var(--accent); }
.action-dislike { background: var(--danger); }
.btn {
  border: 0;
  border-radius: var(--radius);
  padding: 15px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.95); opacity: 0.9; }
.btn-approve { background: var(--accent); }
.btn-reject { background: var(--danger); }
.btn-ghost {
  flex: 0 0 auto;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--fg);
  font-size: 19px;
  padding: 14px 16px;
}
.btn-info {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  font-size: 19px;
}
.btn-dark { background: #26262e; width: 100%; margin-top: 10px; }

/* ---- Шторки ---- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  z-index: 40;
}
.sheet-card {
  width: 100%;
  background: #17171f;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 70vh;
  overflow-y: auto;
}
.sheet-card h3 { margin: 0 0 10px; font-size: 17px; }
.sheet-card p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: #dddde6; white-space: pre-wrap; }
.sheet-card dl { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.sheet-card dl div { display: flex; gap: 8px; padding: 3px 0; }
.sheet-card dt { min-width: 110px; }
.sheet-card dd { margin: 0; color: var(--fg); }
/* Бейдж типа видео (F2): pill под текстом карточки — тихий, минималистичный */
.type-badge {
  display: inline-flex;
  align-items: center;
  margin: 0 0 12px;
  padding: 5px 11px;
  border: 1px solid #2b2b36;
  border-radius: 999px;
  background: #1e1e27;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip-btn {
  border: 1px solid #33333d;
  background: #22222b;
  color: var(--fg);
  font-size: 14px;
  padding: 10px 15px;
  cursor: pointer;
}
.chip-btn:active { background: #2e2e39; }

/* ---- Пилюля звука поверх видео (стиль Instagram): градиентное стекло,
   тонкие аутлайн-иконки, плавный fade появления по тапу, без кричащих цветов ---- */
.sound-btn {
  position: absolute;
  right: 14px;
  bottom: calc(128px + var(--safe-bottom));
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 3;
  /* по умолчанию погашена: появляется fade-ом по тапу (см. flashSoundButton) */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
}
.sound-btn.visible { opacity: 1; pointer-events: auto; }
.sound-btn:active { transform: scale(0.92); }
/* Две иконки друг поверх друга — плавный кроссфейд звук/без звука */
.sound-btn .ic {
  position: absolute;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.sound-btn .ic-on { opacity: 0; transform: scale(0.85); }
.sound-btn .ic-off { opacity: 1; transform: scale(1); }
.sound-btn.is-on .ic-on { opacity: 1; transform: scale(1); }
.sound-btn.is-on .ic-off { opacity: 0; transform: scale(0.85); }

/* ---- Прогресс-бар внизу карточки (Instagram Reels): тонкий таймлайн всего
   ролика в самом низу, над safe-area; тап/перетаскивание = перемотка;
   пройденная часть подсвечена. Кнопки ✅/🗑 расположены выше и не мешают. ---- */
.seek-bar {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  height: calc(20px + var(--safe-bottom));
  padding: 0 0 calc(4px + var(--safe-bottom));
  display: flex;
  align-items: flex-end;
  z-index: 4;
  touch-action: none; /* перетаскивание бара не уходит в свайп ленты */
  cursor: pointer;
}
.seek-track {
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
  transition: height 0.15s ease;
}
.seek-bar.scrubbing .seek-track { height: 5px; } /* чуть толще при перемотке */
.seek-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92); /* подсветка пройденной части */
}

/* ---- Финал / заглушки ---- */
.done {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  text-align: center;
}
.done-inner { padding: 24px; max-width: 420px; }
.done-emoji { font-size: 64px; margin-bottom: 8px; }
.done h2 { margin: 0 0 12px; font-size: 24px; }
.done-summary { font-size: 16px; margin: 0 0 10px; }
.done-thanks { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 22px; }
/* Код ошибки (error_id) — для точного поиска события в логах */
.error-code { color: var(--muted); font-size: 12px; letter-spacing: .04em; margin: -12px 0 22px; }

/* ---- Тост ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(112px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--fg);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

/* Анимация ухода карточки после решения */
.card.leaving { transition: transform 0.28s ease, opacity 0.28s ease; transform: translateY(-40%); opacity: 0; }

@media (min-width: 700px) {
  .btn { padding: 16px 26px; }
  #controls { max-width: 560px; left: 50%; transform: translateX(-50%); }
}
