/* ===================================================================
   Video Memories — Instagram Reels–style full-screen vertical feed
   =================================================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #fff;
  font-family: "Poppins", sans-serif;
  overscroll-behavior-y: contain;
}

body {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
}

/* ---------- Top bar ---------- */
.reels-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 26px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
  pointer-events: none;
}
.reels-topbar > * { pointer-events: auto; }

.reels-back,
.reels-mute {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.2s ease, background 0.2s ease;
}
.reels-back:hover,
.reels-mute:hover { background: rgba(255, 255, 255, 0.22); }
.reels-back:active,
.reels-mute:active { transform: scale(0.92); }

.reels-title {
  font-family: "Dancing Script", cursive;
  font-size: 1.35rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.reels-mute .icon-unmuted { display: none; }
.reels-mute[aria-pressed="false"] .icon-muted { display: none; }
.reels-mute[aria-pressed="false"] .icon-unmuted { display: block; }

/* ---------- Feed ---------- */
.reels-feed {
  height: 100%;
  width: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  /* Instagram/TikTok let the finger's own momentum drive the snap rather
     than layering CSS smooth-scroll on top of it — mixing the two is
     what causes the slight jitter/overshoot on a fast swipe. JS still
     asks for {behavior:"smooth"} explicitly for the few programmatic
     jumps (loop-back, arrow keys), so nothing there is lost. */
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: none;
  outline: none;
}
.reels-feed::-webkit-scrollbar { display: none; }

.reel {
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  contain: layout paint style;
}

.reel-video,
.reel-bg-blur {
  will-change: transform;
  backface-visibility: hidden;
}

/* ---------- Persistent blurred backdrop ----------
   Always present, always the same clip as the foreground video, scaled +
   blurred. On mobile it only shows through letterbox gaps (landscape
   clips); on desktop it fills the whole browser window as ambient
   background around the phone-shaped frame. */
.reel-bg-blur {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(35px) brightness(0.45) saturate(1.1);
  transform: scale(1.2);
  pointer-events: none;
}

/* ---------- The "phone" frame ----------
   Mobile: fills the entire reel (edge-to-edge, classic reels feel).
   Desktop: a centered, rounded, shadowed vertical panel — like opening
   Reels/Shorts on a laptop — so a portrait clip never gets stretched to
   fill a landscape browser window. */
.reel-frame {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
}

@media (min-width: 860px) {
  .reel-frame {
    inset: auto;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    height: 90vh;
    height: 90dvh;
    width: calc(90vh * 9 / 16);
    width: calc(90dvh * 9 / 16);
    max-width: 460px;
    max-height: 860px;
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08),
      0 0 70px rgba(255, 60, 110, 0.16);
  }
}

/* ---------- Ambient floating hearts (desktop ambient glow only) ---------- */
.reel-ambient-hearts { display: none; }

@media (min-width: 860px) {
  .reel-ambient-hearts {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
  }
}

.ambient-heart {
  position: absolute;
  bottom: -10%;
  font-size: var(--size, 16px);
  color: rgba(255, 130, 160, 0.4);
  opacity: 0;
  animation: ambient-heart-float var(--dur, 12s) ease-in infinite;
  animation-delay: var(--delay, 0s);
  filter: drop-shadow(0 0 6px rgba(255, 90, 130, 0.25));
}

@keyframes ambient-heart-float {
  0% { transform: translateY(0) translateX(0) rotate(0deg); opacity: 0; }
  12% { opacity: 0.65; }
  50% { transform: translateY(-55vh) translateX(var(--drift, 12px)) rotate(12deg); }
  88% { opacity: 0.3; }
  100% { transform: translateY(-105vh) translateX(calc(var(--drift, 12px) * -1)) rotate(-10deg); opacity: 0; }
}

/* ---------- Per-video scrub progress bar (TikTok/Stories-style) ---------- */
.reel-scrub {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  height: 2.5px;
  background: rgba(255, 255, 255, 0.22);
}
.reel-scrub-fill {
  height: 100%;
  width: 0%;
  background: #ff2f56;
  box-shadow: 0 0 6px rgba(255, 47, 86, 0.6);
  transition: width 0.12s linear;
}

/* ---------- Error state: shown if a clip fails to load ---------- */
.reel-error {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 30px;
  text-align: center;
  background: rgba(10, 6, 8, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.reel-error[hidden] { display: none; }
.reel-error p {
  margin: 0;
  font-family: "Poppins", sans-serif;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}
.reel-error-retry {
  padding: 10px 24px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.reel-error-retry:hover { background: rgba(255, 47, 86, 0.25); }
.reel-error-retry:active { transform: scale(0.95); }

/* ---------- Video layer ---------- */
.reel-video-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
}

/* portrait / vertical source (the common case): fill the whole frame */
.reel-video {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* landscape (or square) source: show the whole frame, letterboxed over the
   blurred backdrop so there's never a hard black bar */
.reel.is-landscape .reel-video {
  object-fit: contain;
  background: transparent;
}
.reel.is-landscape .reel-video-wrap {
  background: transparent;
}

/* ---------- Tap-to-play/pause flash icon ---------- */
.reel-tap-icon {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  color: #fff;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.reel-tap-icon .icon-pause { display: none; }
.reel-tap-icon.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.reel-tap-icon.show.is-pause .icon-play { display: none; }
.reel-tap-icon.show.is-pause .icon-pause { display: block; }

/* ---------- Double-tap heart burst ---------- */
.reel-heart-burst {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 4px 18px rgba(0, 0, 0, 0.45));
}
.reel-heart-burst.burst {
  animation: reel-heart-burst-play 0.9s cubic-bezier(0.22, 1.4, 0.36, 1);
}
@keyframes reel-heart-burst-play {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  55% { transform: translate(-50%, -50%) scale(0.95); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
}

/* ---------- Bottom caption overlay ---------- */
.reel-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  padding: 60px 84px calc(env(safe-area-inset-bottom, 0px) + 26px) 20px;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.62) 0%, rgba(0, 0, 0, 0) 100%);
  pointer-events: none;
}
.reel-caption {
  margin: 0;
  font-family: "Dancing Script", cursive;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  line-height: 1.35;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ---------- Right-side action rail (like + download controls) ---------- */
.reel-actions {
  position: absolute;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* ---------- Shared Apple-style glass treatment (like + download) ---------- */
.reel-like-btn,
.reel-download-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  background: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 255, 255, 0.08) 55%,
    rgba(255, 255, 255, 0.14) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.22),
    0 1px 2px rgba(0, 0, 0, 0.15),
    inset 0 1px 1px rgba(255, 255, 255, 0.55),
    inset 0 -1px 1px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.25s ease, box-shadow 0.25s ease;
}
.reel-like-btn:hover,
.reel-download-btn:hover {
  background: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.3) 0%,
    rgba(255, 255, 255, 0.12) 55%,
    rgba(255, 255, 255, 0.2) 100%
  );
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.26),
    inset 0 1px 1px rgba(255, 255, 255, 0.65),
    inset 0 -1px 1px rgba(0, 0, 0, 0.12);
}
.reel-like-btn:active,
.reel-download-btn:active { transform: scale(0.88); }

/* ---------- Like button ---------- */
.reel-like-btn .icon-heart-filled { display: none; color: #ff2f56; }
.reel-like-btn[aria-pressed="true"] .icon-heart-outline { display: none; }
.reel-like-btn[aria-pressed="true"] .icon-heart-filled { display: block; }
.reel-like-btn.pop { animation: reel-like-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes reel-like-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.reel-like-btn[aria-pressed="true"] {
  background: linear-gradient(
    155deg,
    rgba(255, 90, 120, 0.32) 0%,
    rgba(255, 47, 86, 0.16) 55%,
    rgba(255, 90, 120, 0.24) 100%
  );
  border-color: rgba(255, 120, 150, 0.5);
  box-shadow:
    0 8px 24px rgba(255, 47, 86, 0.28),
    inset 0 1px 1px rgba(255, 255, 255, 0.4),
    inset 0 -1px 1px rgba(0, 0, 0, 0.1);
}

/* ---------- Little hearts that rise from the like button ---------- */
.reel-mini-heart {
  position: absolute;
  right: 16px;
  bottom: 96px;
  z-index: 7;
  font-size: var(--mh-size, 16px);
  color: #ff2f56;
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
  animation: reel-mini-heart-rise 1.15s ease-out forwards;
}
@keyframes reel-mini-heart-rise {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5) rotate(0deg); }
  15% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(var(--mh-drift, 0px), -150px) scale(1) rotate(var(--mh-rot, 0deg));
  }
}

/* ---------- Download button ---------- */
.reel-download-btn {
  position: relative; /* anchors the loading ring/pulse below */
}

.reel-download-btn .icon-download-check { display: none; color: #4ade80; }
.reel-download-btn.done .icon-download { display: none; }
.reel-download-btn.done .icon-download-check { display: block; }
.reel-download-btn.pop { animation: reel-like-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* prominent in-progress state */
.reel-download-btn.loading {
  background: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.32) 0%,
    rgba(255, 255, 255, 0.14) 55%,
    rgba(255, 255, 255, 0.22) 100%
  );
}
.reel-download-btn.loading .icon-download {
  animation: reel-download-pulse 0.9s ease-in-out infinite;
}
@keyframes reel-download-pulse {
  0%, 100% { transform: translateY(0) scale(1); opacity: 1; }
  50% { transform: translateY(2px) scale(0.9); opacity: 0.55; }
}

/* spinning ring around the button while the fetch is in flight */
.reel-download-btn.loading::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  border-top-color: #fff;
  border-right-color: rgba(255, 255, 255, 0.55);
  animation: reel-download-spin 0.7s linear infinite;
}

/* soft outward pulse ring so it reads clearly even out of the corner of the eye */
.reel-download-btn.loading::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  animation: reel-download-ring-pulse 1.2s ease-out infinite;
}

@keyframes reel-download-spin {
  to { transform: rotate(360deg); }
}
@keyframes reel-download-ring-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* success flash when done */
.reel-download-btn.done {
  background: linear-gradient(
    155deg,
    rgba(74, 222, 128, 0.34) 0%,
    rgba(74, 222, 128, 0.16) 55%,
    rgba(74, 222, 128, 0.24) 100%
  );
  border-color: rgba(120, 255, 170, 0.5);
  animation: reel-download-done-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes reel-download-done-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- End-of-feed card ---------- */
.reel-end { background: radial-gradient(ellipse at 50% 30%, #2a1420 0%, #120a10 70%, #000 100%); }
.reel-end::before { display: none; }

.reel-end-hearts {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.reel-end-frame {
  position: relative;
  inset: auto;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  display: grid;
  place-items: center;
}

@media (min-width: 860px) {
  .reel-end-frame {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    height: 90vh;
    height: 90dvh;
    width: calc(90vh * 9 / 16);
    width: calc(90dvh * 9 / 16);
    max-width: 460px;
    max-height: 860px;
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08),
      0 0 70px rgba(255, 60, 110, 0.16);
    background: radial-gradient(ellipse at 50% 30%, #2a1420 0%, #120a10 70%, #000 100%);
  }
}

.reel-end-content {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 40px;
  text-align: center;
}
.reel-end-heart {
  font-size: 40px;
  color: #ff2f56;
  filter: drop-shadow(0 0 18px rgba(255, 47, 86, 0.55));
  animation: reel-end-heartbeat 1.8s ease-in-out infinite;
}
@keyframes reel-end-heartbeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.14); }
}
.reel-end-title {
  margin: 4px 0 0;
  font-family: "Dancing Script", cursive;
  font-size: 1.7rem;
  line-height: 1.3;
}
.reel-end-sub {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.65);
}
.reel-end-replay {
  margin-top: 14px;
  padding: 11px 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}
.reel-end-replay:hover { background: rgba(255, 47, 86, 0.25); }
.reel-end-replay:active { transform: scale(0.95); }

/* ---------- First-visit swipe hint ---------- */
.reels-swipe-hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  transform: translateX(-50%);
  z-index: 38;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: rgba(255, 255, 255, 0.85);
  font-family: "Poppins", sans-serif;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.reels-swipe-hint.show {
  opacity: 1;
  animation: reels-hint-bounce 1.6s ease-in-out infinite;
}
@keyframes reels-hint-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-8px); }
}

/* ---------- First-ever-visit welcome note ---------- */
.reels-welcome {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) scale(0.94);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 34px;
  border-radius: 20px;
  background: rgba(15, 8, 11, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.reels-welcome.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.reels-welcome-heart {
  font-size: 28px;
  color: #ff2f56;
  filter: drop-shadow(0 0 14px rgba(255, 47, 86, 0.5));
  animation: reel-end-heartbeat 1.8s ease-in-out infinite;
}
.reels-welcome p {
  margin: 0;
  font-family: "Dancing Script", cursive;
  font-size: 1.3rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ---------- Loading shimmer while a video's src hasn't loaded yet ---------- */
.reel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(135deg, #1a1015, #241318, #1a1015);
}

@media (prefers-reduced-motion: reduce) {
  .reel-tap-icon,
  .reel-heart-burst,
  .reel-like-btn,
  .ambient-heart,
  .reel-mini-heart,
  .reel-end-heart,
  .reels-swipe-hint.show,
  .ambient-heart, .reel-mini-heart { display: none; }
}