/**
 * StreamVisión · Clip Recorder v3
 *
 * Cambios respecto a v2:
 *  - Fullscreen overlay propio (no usa Fullscreen API nativa)
 *  - Contador integrado EN el botón circular (no píldora aparte)
 *  - Botón "Volver al sitio" flotante abajo
 *  - Modal compartir adaptado a móvil (1 botón) vs PC (3 botones)
 *  - Mensaje "Rota tu teléfono" en portrait
 *  - Animaciones suaves de entrada/salida
 */

/* ============ VARIABLES con fallbacks ============ */
.sv-clip-fs-overlay,
.sv-clip-modal-backdrop,
.sv-clip-orientation-msg,
.sv-clip-toast {
  --sv-accent: var(--accent, #9aff3a);
  --sv-accent-deep: #6bcc1f;
  --sv-bg-base: var(--bg, #050807);
  --sv-bg-card: var(--bg-card, #0d1210);
  --sv-bg-elev: var(--bg-elevated, #161d18);
  --sv-border: var(--border, #1f2923);
  --sv-border-strong: var(--border-strong, #2d3a32);
  --sv-text: var(--text, #f5f4ed);
  --sv-text-muted: var(--text-muted, #7d8881);
  --sv-red: var(--red, #ff3a5d);
  --sv-rec: #ff3a3a;
}

/* ============ FULLSCREEN OVERLAY ============ */
/*
 * Este overlay aparece cuando el video se reproduce.
 * El <video> es movido aquí dinámicamente con JS.
 */
.sv-clip-fs-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9000;
  display: none;
  flex-direction: column;
  align-items: stretch;
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Body locking */
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.sv-clip-fs-overlay.is-open {
  display: flex;
  opacity: 1;
}

.sv-clip-fs-overlay.is-closing {
  opacity: 0;
}

/* ============ VIDEO HOST DENTRO DEL OVERLAY ============ */
.sv-clip-fs-video-host {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.sv-clip-fs-video-host video {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  display: block;
  background: #000;
}

/* Mientras la app está en fullscreen, ocultar el video original sin perderlo */
.sv-clip-source-host-hidden {
  visibility: hidden !important;
}

/* ============ HEADER (info + cerrar) ============ */
.sv-clip-fs-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  pointer-events: none;
}

.sv-clip-fs-header > * { pointer-events: auto; }

.sv-clip-fs-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  color: white;
  font-family: 'Outfit', system-ui, sans-serif;
}

.sv-clip-fs-info .court {
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  font-size: 0.7rem;
  color: var(--sv-accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sv-clip-fs-info .court::before {
  content: '';
  width: 7px; height: 7px;
  background: var(--sv-accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--sv-accent);
}

.sv-clip-fs-info .time {
  font-size: 0.92rem;
  font-weight: 600;
  color: white;
}

/* Botón cerrar arriba a la derecha (small, para evitar accidentes) */
.sv-clip-fs-close-x {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.sv-clip-fs-close-x:hover {
  background: rgba(0,0,0,0.75);
}

/* ============ FOOTER (botón grabar + volver) ============ */
.sv-clip-fs-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 12;
  padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  background: linear-gradient(0deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  pointer-events: none;
}

.sv-clip-fs-footer > * { pointer-events: auto; }

/* Hint primera vez */
.sv-clip-hint {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: white;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
  animation: svFadeUp 0.5s ease;
  white-space: nowrap;
}

.sv-clip-hint::before {
  content: '👆 ';
}

@keyframes svFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ BOTÓN GRABAR CIRCULAR ============ */
.sv-clip-recbtn {
  --size: 76px;
  position: relative;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* Anillo translúcido de fondo */
.sv-clip-recbtn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255,255,255,0.3);
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
}

.sv-clip-recbtn:hover::before { border-color: rgba(255,255,255,0.6); }
.sv-clip-recbtn:active::before { transform: scale(0.94); }

.sv-clip-recbtn.is-recording::before {
  background: rgba(255,58,58,0.15);
  border-color: var(--sv-rec);
}

/* SVG progress circular */
.sv-clip-recbtn svg.progress {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
  z-index: 1;
}

.sv-clip-recbtn .progress-track {
  fill: none;
  stroke: rgba(255,255,255,0.12);
  stroke-width: 3;
}

.sv-clip-recbtn .progress-fill {
  fill: none;
  stroke: var(--sv-accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 226.2; /* 2π × 36 (radio para size=76) */
  stroke-dashoffset: 226.2;
  transition: stroke-dashoffset 0.1s linear;
  filter: drop-shadow(0 0 6px rgba(154,255,58,0.5));
}

/* Centro: punto rojo (idle) | contador (grabando) */
.sv-clip-recbtn .core {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transition: all 0.25s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.sv-clip-recbtn .core .dot {
  width: 22px;
  height: 22px;
  background: var(--sv-rec);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255,58,58,0.6);
  transition: opacity 0.2s;
}

.sv-clip-recbtn .core .counter {
  display: none;
  font-family: 'Anton', sans-serif;
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  font-weight: normal;
  letter-spacing: 0.01em;
}

.sv-clip-recbtn .core .counter .max {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.55rem;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  margin-top: 1px;
  letter-spacing: 0.06em;
}

.sv-clip-recbtn.is-recording .core .dot { display: none; }
.sv-clip-recbtn.is-recording .core .counter { display: block; text-align: center; }

/* Botón "Volver al sitio" */
.sv-clip-fs-back {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  color: white;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.sv-clip-fs-back:hover {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.3);
}

.sv-clip-fs-back svg {
  width: 14px;
  height: 14px;
}

/* ============ MENSAJE DE ORIENTACIÓN ============ */
.sv-clip-orientation-msg {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  color: white;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  text-align: center;
  z-index: 11;
  display: none;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Outfit', system-ui, sans-serif;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.sv-clip-orientation-msg.show {
  display: inline-flex;
  opacity: 1;
}
.sv-clip-orientation-msg.fade-out {
  opacity: 0;
}
.sv-clip-orientation-msg .icon {
  font-size: 1rem;
}
.sv-clip-orientation-msg .text {
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ============ MODAL COMPARTIR ============ */
.sv-clip-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10000;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: svModalFadeIn 0.2s ease;
}

@media (min-width: 640px) {
  .sv-clip-modal-backdrop { align-items: center; padding: 1rem; }
}

.sv-clip-modal-backdrop.is-open { display: flex; }

@keyframes svModalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.sv-clip-modal {
  background: white;
  color: #0d1210;
  border-radius: 24px 24px 0 0;
  padding: 1.75rem 1.5rem 2.25rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  position: relative;
  animation: svModalSlideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (min-width: 640px) {
  .sv-clip-modal {
    border-radius: 24px;
    animation: svModalScaleIn 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}

@keyframes svModalSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes svModalScaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.sv-clip-modal h3 {
  font-family: 'Anton', sans-serif;
  font-size: 1.6rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  letter-spacing: 0.01em;
  color: #0d1210;
}

.sv-clip-modal .subtitle {
  color: #7d8881;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  font-family: 'Outfit', system-ui, sans-serif;
}

.sv-clip-modal .step-indicator {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: var(--sv-accent-deep);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 1.25rem;
}

.sv-clip-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(107,204,31,0.18);
  border-top-color: var(--sv-accent-deep);
  border-radius: 50%;
  margin: 0 auto 1.25rem;
  animation: svClipSpin 0.9s linear infinite;
}

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

.sv-clip-modal .actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.5rem;
}
/* Fila de botones lado a lado (Copiar + Descargar) */
.sv-clip-btn-row {
  display: flex;
  gap: 0.65rem;
}
.sv-clip-btn-row .sv-clip-btn {
  flex: 1;
}
/* Cajita de guia para iPhone */
.sv-clip-ios-hint {
  margin-top: 0.25rem;
  padding: 0.7rem 0.85rem;
  background: rgba(58,185,255,0.08);
  border: 1px solid rgba(58,185,255,0.25);
  border-radius: 12px;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #5a6b75;
}
.sv-clip-ios-hint strong { color: #0d1210; font-weight: 700; }

.sv-clip-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  padding: 1.05rem 1.2rem;
  border-radius: 14px;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
  background: white;
  color: #0d1210;
  transition: transform 0.12s, box-shadow 0.2s, background 0.15s;
  text-decoration: none;
}

.sv-clip-btn:active { transform: scale(0.98); }

/* Botón principal: gradiente único StreamVisión */
.sv-clip-btn-share-native {
  background: linear-gradient(135deg, #6bcc1f 0%, #9aff3a 100%);
  color: #050807;
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(154,255,58,0.35);
}
.sv-clip-btn-share-native:hover { box-shadow: 0 8px 24px rgba(154,255,58,0.5); }

.sv-clip-btn-whatsapp {
  background: #25d366;
  color: white;
  border-color: #1da851;
}

.sv-clip-btn-download {
  background: #0d1210;
  color: white;
  border-color: #0d1210;
}

.sv-clip-btn-link,
.sv-clip-btn-summary {
  background: white;
  color: #0d1210;
  border-color: #e0e0e0;
}

.sv-clip-btn-ghost {
  background: transparent;
  color: #7d8881;
  border-color: transparent;
  padding-top: 0.7rem;
  padding-bottom: 0.7rem;
  font-weight: 600;
}

/* Preview del clip dentro del modal */
.sv-clip-modal video.preview {
  width: 100%;
  max-height: 240px;
  border-radius: 12px;
  background: #000;
  margin-bottom: 1rem;
  display: block;
}

/* ============ TOAST ============ */
.sv-clip-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: #0d1210;
  color: white;
  padding: 0.85rem 1.4rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 10001;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  pointer-events: none;
}

.sv-clip-toast.show { transform: translateX(-50%) translateY(0); }

/* ============ BLOQUEAR SCROLL del body cuando fullscreen abierto ============ */
body.sv-clip-fs-locked {
  overflow: hidden !important;
  position: fixed;
  inset: 0;
  width: 100%;
}

/* ============= FLECHAS DE NAVEGACION ENTRE CHUNKS ============= */
.sv-clip-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: all 0.15s ease;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.sv-clip-nav-arrow:hover,
.sv-clip-nav-arrow:active {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-50%) scale(1.05);
}
.sv-clip-nav-arrow svg {
  width: 28px;
  height: 28px;
}
.sv-clip-nav-prev { left: 12px; }
.sv-clip-nav-next { right: 12px; }

@media (max-width: 480px) {
  .sv-clip-nav-arrow { width: 48px; height: 48px; }
  .sv-clip-nav-arrow svg { width: 24px; height: 24px; }
}
