/* ============================================================
   Photo Overlay & Share — Custom Styles
   Versión: 1.0
   ============================================================ */

/* ── Custom Properties (theming) ─────────────────────────── */
:root {
  --brand-primary:    #E91E8C;
  --brand-secondary:  #9C27B0;
  --brand-gradient:   linear-gradient(135deg, #E91E8C 0%, #9C27B0 100%);
  --bg-dark:          #0a0a0f;
  --bg-card:          #13131a;
  --bg-overlay:       rgba(0, 0, 0, 0.55);
  --text-primary:     #ffffff;
  --text-muted:       rgba(255,255,255,0.55);
  --border-color:     rgba(255,255,255,0.12);
  --radius-lg:        20px;
  --radius-xl:        28px;
  --transition:       0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset / Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* Prevent iOS text size adjust on rotate */
html { -webkit-text-size-adjust: 100%; }

/* ── App Screens ──────────────────────────────────────────── */
.app-screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-dark);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  transform: translateY(20px);
  z-index: 10;
}

.app-screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
  z-index: 20;
}

.app-screen.slide-out {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
}

/* ── SCREEN 1: WELCOME ───────────────────────────────────── */
.welcome-bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(233,30,140,0.18) 0%, transparent 70%),
              radial-gradient(ellipse 60% 50% at 80% 100%, rgba(156,39,176,0.15) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.welcome-content {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* Logo */
.brand-logo { min-height: 90px; display: flex; align-items: center; justify-content: center; }
.logo-img { max-height: 80px; max-width: 200px; object-fit: contain; }
.logo-placeholder {
  width: 72px; height: 72px;
  background: var(--brand-gradient);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  box-shadow: 0 8px 32px rgba(233,30,140,0.4);
}

/* Hero text */
.welcome-title {
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}
.welcome-title .accent {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Steps */
.steps-list {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.step-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.step-icon {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(233,30,140,0.15);
  border: 1px solid rgba(233,30,140,0.3);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand-primary);
  font-size: 0.9rem;
}

/* CTA Button */
.btn-cta {
  background: var(--brand-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-xl);
  padding: 1rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  box-shadow: 0 8px 24px rgba(233,30,140,0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-cta:hover, .btn-cta:focus {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(233,30,140,0.5);
}
.btn-cta:active { transform: scale(0.97); opacity: 0.9; }
.btn-cta:disabled { opacity: 0.5; transform: none; box-shadow: none; cursor: not-allowed; }

/* Ghost & outline buttons */
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 0.85rem 2rem;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); color: #fff; border-color: rgba(255,255,255,0.25); }
.btn-ghost:active { opacity: 0.8; }

.btn-secondary-outline {
  background: transparent;
  color: var(--brand-primary);
  border: 1.5px solid var(--brand-primary);
  border-radius: var(--radius-xl);
  padding: 0.85rem 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
}
.btn-secondary-outline:hover { background: rgba(233,30,140,0.1); color: var(--brand-primary); }
.btn-secondary-outline:active { opacity: 0.8; }

/* Privacy note */
.privacy-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

/* ── SCREEN 2: FRAME SELECTOR ───────────────────────────── */
.frames-header {
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.frames-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}
.frames-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Área scrollable con la grilla */
.frames-scroll-area {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Grilla 2 columnas */
.frames-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding-top: 12px;
}

/* Tarjeta de marco */
.frame-card {
  position: relative;
  aspect-ratio: 9/16;
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  border: 2.5px solid transparent;
  background: var(--bg-card);
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.frame-card:active { transform: scale(0.97); }

/* Imagen del marco dentro de la tarjeta */
.frame-card-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  /* Fondo degradado para que el marco se vea aunque tenga partes transparentes */
  background: radial-gradient(ellipse at center, #1e1e2e 0%, #0a0a0f 100%);
}

/* Nombre del marco */
.frame-card-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 6px 8px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Check de selección */
.frame-card-check {
  position: absolute;
  top: 8px; right: 8px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--brand-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  color: #fff;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 2px 8px rgba(233,30,140,0.5);
}

/* Estado: seleccionado */
.frame-card.selected {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 1px var(--brand-primary), 0 4px 20px rgba(233,30,140,0.3);
}
.frame-card.selected .frame-card-check {
  opacity: 1;
  transform: scale(1);
}

/* Estado vacío */
.frames-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* Footer fijo con botón */
.frames-footer {
  flex-shrink: 0;
  background: var(--bg-dark);
  border-top: 1px solid var(--border-color);
}

/* Skeleton loader */
@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}
.frame-card.skeleton {
  cursor: default;
  background: linear-gradient(90deg,
    var(--bg-card) 25%,
    rgba(255,255,255,0.05) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-color: transparent;
}

/* ── SCREEN 3: CAMERA ────────────────────────────────────── */
.camera-wrapper {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/*
 * Viewport 9:16 siempre portrait, centrado en pantalla.
 * En móvil portrait ocupa todo. En desktop/landscape queda
 * una columna centrada con barras negras a los lados.
 */
.camera-viewport {
  position: relative;
  /* Altura = 100vh, ancho = 100vh * 9/16 */
  height: 100vh;
  width: calc(100vh * 9 / 16);
  /* En pantallas muy anchas no superar el 100vw */
  max-width: 100vw;
  max-height: calc(100vw * 16 / 9);
  background: #000;
  overflow: hidden;
  flex-shrink: 0;
}

#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* espejo frontal */
}
#camera-video.no-mirror {
  transform: scaleX(1);
}

/* Frame overlay — exactamente sobre el viewport 9:16 */
.frame-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* fill: el viewport YA es 9:16, igual que el marco → sin distorsión */
  object-fit: fill;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.25s ease;
}
.frame-overlay.processing {
  opacity: 0;
}

/* Top bar */
.camera-top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 16px) 16px 16px;
  padding-top: max(env(safe-area-inset-top), 16px);
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
}
.camera-hint {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.8);
  text-align: center;
  flex: 1;
  padding: 0 8px;
}

/* Icon buttons (top bar) */
.btn-icon {
  width: 44px; height: 44px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }
.btn-icon:active { transform: scale(0.93); }

/* Bottom bar with capture button */
.camera-bottom-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: max(env(safe-area-inset-bottom), 32px);
  padding-top: 20px;
  background: linear-gradient(to top, rgba(0,0,0,0.65) 0%, transparent 100%);
}

/* Capture button */
.capture-ring {
  width: 84px; height: 84px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.8);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s;
}
.btn-capture {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: #fff;
  border: none;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: transform 0.12s ease, background 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.capture-inner {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0,0,0,0.08);
  display: block;
  transition: transform 0.12s ease;
}
.btn-capture:active .capture-inner { transform: scale(0.88); }
.btn-capture:active { transform: scale(0.95); }
.btn-capture.capturing { background: var(--brand-primary); }

/* Flash animation on capture */
@keyframes flash {
  0%   { opacity: 0; }
  10%  { opacity: 0.85; }
  100% { opacity: 0; }
}
.camera-flash {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 999;
  pointer-events: none;
  animation: flash 0.45s ease-out forwards;
}

/* ── SCREEN 3: PREVIEW ───────────────────────────────────── */
.preview-wrapper {
  position: relative;
  background: var(--bg-dark);
}

.preview-canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  min-height: 0;
}

#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.preview-actions {
  flex-shrink: 0;
  background: var(--bg-dark);
  border-top: 1px solid var(--border-color);
}

/* Share status message */
.share-status-msg {
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
}
.share-status-msg.success {
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.3);
  color: #4ade80;
}
.share-status-msg.error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: #f87171;
}
.share-status-msg.info {
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.3);
  color: #60a5fa;
}

/* ── LOADING OVERLAY ─────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,15,0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}

/* ── Error Modal ─────────────────────────────────────────── */
#errorModal .modal-content {
  border-radius: var(--radius-xl) !important;
  background: var(--bg-card) !important;
  box-shadow: 0 25px 80px rgba(0,0,0,0.6);
}
.error-icon {
  width: 64px; height: 64px;
  background: rgba(234,179,8,0.12);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto;
}

/* ── Accessibility / touch ───────────────────────────────── */
button:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 3px;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* ── Safe area padding fix for notched devices ───────────── */
@supports (padding: max(0px)) {
  .welcome-content { padding-top: max(20px, env(safe-area-inset-top)) !important; }
  .preview-actions { padding-bottom: max(16px, env(safe-area-inset-bottom)) !important; }
}
