/* ─── Stories Overlay ─── */
.stories-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.stories-overlay.active {
  pointer-events: all;
  opacity: 1;
}

.stories-overlay.closing {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* ─── Close Button ─── */
.story-close-btn {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1010;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease;
  opacity: 0;
  transform: scale(0.9);
}

.stories-overlay.active .story-close-btn {
  opacity: 1;
  transform: scale(1);
  transition-delay: 0.25s;
}

.stories-overlay.closing .story-close-btn {
  opacity: 0;
  transform: scale(0.9);
  transition-delay: 0s;
  transition-duration: 0.15s;
}

.story-close-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.08);
}

.story-close-btn:active { transform: scale(0.9); }

.story-close-btn svg {
  width: 24px;
  height: 24px;
}

/* ─── Story Viewer ─── */
.story-viewer {
  position: relative;
  height: min(95vh, calc(100vh - 48px));
  aspect-ratio: 9 / 16;
  width: auto;
  max-width: min(90vw, calc(100vw - 48px));
  overflow: hidden;
  background: #0a0a0a;
  border-radius: 16px;
  opacity: 0;
  transition: opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.06);
}

.stories-overlay.active .story-viewer {
  opacity: 1;
}

.stories-overlay.closing .story-viewer {
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* ─── Story Header ─── */
.story-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px;
}

.story-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 100px;
  background: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 100%);
  pointer-events: none;
  z-index: -1;
  border-radius: 16px 16px 0 0;
}

.story-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.story-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.story-username {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  letter-spacing: -0.02em;
}

/* ─── Progress Bars ─── */
.story-progress {
  display: flex;
  gap: 4px;
  z-index: 10;
}

.story-bar {
  flex: 1;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  overflow: hidden;
}

.story-bar.active-track { background: rgba(255, 255, 255, 0.16); }

.story-bar-fill {
  height: 100%;
  background: #fff;
  border-radius: 16px;
  width: 0%;
  transition: width linear;
}

.story-bar.done .story-bar-fill { width: 100%; transition: none; }

/* ─── Content ─── */
.story-content { width: 100%; height: 100%; position: relative; }

.story-slide {
  display: none;
  width: 100%; height: 100%;
  position: absolute;
  inset: 0;
}

.story-slide.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 80px 32px 60px;
  animation: storyFadeIn 0.35s var(--ease-out);
}

.story-slide:nth-child(1) { background: linear-gradient(145deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%); }
.story-slide:nth-child(2) { background: linear-gradient(145deg, #0f0c29 0%, #302b63 50%, #24243e 100%); }
.story-slide:nth-child(3) { background: linear-gradient(145deg, #141e30 0%, #243b55 100%); }
.story-slide:nth-child(4) { background: linear-gradient(145deg, #1a1a2e 0%, #2d1f3d 100%); }

.story-slide::before {
  content: '';
  position: absolute;
  width: 220px; height: 220px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  pointer-events: none;
  top: 35%; left: 50%;
  transform: translate(-50%, -50%);
}
.story-slide:nth-child(1)::before { background: #4f46e5; }
.story-slide:nth-child(2)::before { background: #7c3aed; }
.story-slide:nth-child(3)::before { background: #06b6d4; }
.story-slide:nth-child(4)::before { background: #f43f5e; }

.story-text-block { text-align: center; color: #fff; position: relative; z-index: 2; }

.story-icon-wrap {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.story-icon-wrap svg { width: 24px; height: 24px; color: rgba(255,255,255,0.8); }

.story-overline {
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 14px;
}

.story-headline {
  font-size: 28px; font-weight: 600;
  line-height: 1.15;
  margin-bottom: 14px;
  color: #fff;
  letter-spacing: -0.02em;
}

.story-body {
  font-size: 15px; font-weight: 400;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.5);
  max-width: 320px;
  margin: 0 auto;
}

.story-numbers {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.story-num-value { font-size: 22px; font-weight: 600; color: #fff; line-height: 1; letter-spacing: -0.02em; }
.story-num-label { font-size: 11px; font-weight: 400; color: rgba(255, 255, 255, 0.3); margin-top: 4px; }

/* Image slides */
.story-slide-image { background: #000 !important; padding: 0 !important; }
.story-slide-image::before, .story-slide-image::after { display: none !important; }

/* ─── Bottom Bar (Footer) ─── */
.story-bottom-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 12;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.story-bottom-bar::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 80px;
  background: linear-gradient(0deg, rgba(0,0,0,0.4) 0%, transparent 100%);
  pointer-events: none;
  z-index: -1;
  border-radius: 0 0 16px 16px;
}

.story-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
  font-weight: 450;
  font-variant-numeric: tabular-nums;
  transition: color 0.25s ease;
}

.story-stat svg { width: 20px; height: 20px; flex-shrink: 0; }

.story-stat-likes { cursor: pointer; user-select: none; position: relative; overflow: visible; }
.story-stat-likes:hover { color: #fff; }

.story-heart-wrap {
  position: relative;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.story-heart-svg {
  width: 20px;
  height: 20px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.story-heart-emoji {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  object-fit: contain;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  transition: opacity 0.2s ease, transform 0.3s var(--ease-out);
  image-rendering: -webkit-optimize-contrast;
}

.story-stat-likes.liked .story-heart-svg {
  opacity: 0;
  transform: scale(0.5);
}

.story-stat-likes.liked .story-heart-emoji {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  animation: heartBounce 0.45s cubic-bezier(0.17, 0.89, 0.32, 1.49);
}

@keyframes heartBounce {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.35); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(0.85); }
  85% { transform: translate(-50%, -50%) scale(1.1); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* Particles */
.heart-particle {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  font-size: 12px;
  line-height: 1;
  opacity: 1;
  animation: heartParticleFly 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.heart-particle img {
  width: 12px;
  height: 12px;
  object-fit: contain;
}

@keyframes heartParticleFly {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0) rotate(var(--rot));
    opacity: 0;
  }
}

/* ─── Tap Zones ─── */
.story-tap-left,
.story-tap-right {
  position: absolute;
  top: 0; bottom: 0;
  width: 35%;
  z-index: 5;
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.story-tap-left { left: 0; }
.story-tap-right { right: 0; width: 65%; }

/* ─── Tablet: keep 9:16 centered ─── */
@media (max-width: 768px) {
  .story-viewer {
    height: min(96vh, calc(100vh - 32px));
  }
  .story-close-btn { top: 16px; right: 16px; }
}

/* ─── Phone portrait: fullscreen ─── */
@media (max-width: 480px) {
  .story-viewer {
    height: 100%;
    width: 100%;
    max-width: 100vw;
    aspect-ratio: auto;
    border-radius: 0 !important;
  }
  .stories-overlay.active .story-viewer { border-radius: 0; }
  .story-close-btn { top: 12px; right: 12px; }
  .story-header::before { border-radius: 0; }
  .story-bottom-bar::before { border-radius: 0; }
}
