/* ===================================================================
   STORIES.CSS — Story viewer overlay (réplica Instagram)
=================================================================== */

/* ---- OVERLAY BASE ---- */
.story-viewer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  /* Fechado por padrão */
  opacity: 0;
  pointer-events: none;
  transform: scale(.96) translateY(8px);
  transition: opacity .22s ease, transform .22s ease;
}

.story-viewer.open {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
}

/* Swipe-down: arrastar para baixo move o viewer */
.story-viewer.swiping {
  transition: none;
}

/* ---- VÍDEO ---- */
#svVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;   /* mostra o vídeo completo sem cortar */
  background: #000;
  display: block;
}

/* ---- BARRAS DE PROGRESSO ---- */
.sv-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 3px;
  padding: 10px 10px 0;
  z-index: 20;
  /* Gradiente para leitura sobre qualquer vídeo */
  background: linear-gradient(to bottom, rgba(0,0,0,.55) 0%, transparent 100%);
  padding-bottom: 48px; /* cobre header também */
  pointer-events: none;
}

.sv-prog-bar {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,.35);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.sv-prog-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: #fff;
  border-radius: 2px;
}

/* Barra já vista: 100% imediato */
.sv-prog-bar.done .sv-prog-fill { width: 100%; }

/* ---- HEADER ---- */
.sv-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 21;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 12px 10px;
  pointer-events: none;
}

.sv-user {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.sv-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(255,255,255,.7);
  flex-shrink: 0;
}

.sv-user-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sv-username {
  font-size: .88rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

.sv-story-title {
  font-size: .75rem;
  color: rgba(255,255,255,.75);
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.sv-actions {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

.sv-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}

.sv-btn:active { background: rgba(255,255,255,.12); }

/* ---- ZONAS DE TOQUE ---- */
.sv-tap {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 22;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sv-tap-left  { left: 0;   width: 30%; }
.sv-tap-right { right: 0;  width: 70%; }

/* ---- FOOTER / LEGENDA ---- */
.sv-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 60px 20px 32px;
  background: linear-gradient(to top, rgba(0,0,0,.7) 0%, transparent 100%);
  pointer-events: none;
}

.sv-caption {
  color: #fff;
  font-size: .95rem;
  line-height: 1.4;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  font-weight: 400;
}

/* ---- LOADING SPINNER ---- */
.sv-loader {
  position: absolute;
  inset: 0;
  z-index: 23;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.sv-loader.visible {
  opacity: 1;
}

.sv-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- HINT DE MUDO ---- */
.sv-mute-hint {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: .82rem;
  padding: 8px 16px;
  border-radius: 20px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}

.sv-mute-hint.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- TELA "TUDO VISTO" ---- */
.sv-end-screen {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  text-align: center;
  padding: 32px;
}

.sv-end-screen h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.sv-end-screen p {
  font-size: .9rem;
  color: rgba(255,255,255,.7);
}

.sv-end-screen .sv-end-replay {
  margin-top: 8px;
  padding: 12px 28px;
  border: 1.5px solid rgba(255,255,255,.5);
  border-radius: 24px;
  background: transparent;
  color: #fff;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}

.sv-end-screen .sv-end-replay:hover { background: rgba(255,255,255,.1); }

.sv-end-screen .sv-end-close {
  color: rgba(255,255,255,.5);
  font-size: .82rem;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
}

/* ---- PAUSA VISUAL ---- */
.story-viewer.paused #svVideo {
  /* Sem filtro — apenas pausa; consistente com Instagram */
}

/* ---- RESPONSIVO ---- */
@media (min-width: 480px) {
  .story-viewer {
    /* Em telas maiores, centraliza com proporção 9:16 */
    background: rgba(0,0,0,.92);
  }

  #svVideo {
    max-width: min(100%, calc(100dvh * 9 / 16));
    max-height: 100dvh;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
  }

  .sv-progress,
  .sv-header,
  .sv-footer,
  .sv-tap {
    max-width: min(100%, calc(100dvh * 9 / 16));
    left: 50%;
    transform: translateX(-50%);
  }

  .sv-tap-left  { left: 50%; margin-left: calc(min(100%, calc(100dvh * 9 / 16)) / -2); }
  .sv-tap-right { right: auto; left: 50%; margin-left: calc(min(100%, calc(100dvh * 9 / 16)) * .3 - min(100%, calc(100dvh * 9 / 16)) / 2); }
}
