/* ===== Variables ===== */
:root {
  --gold: #d4af37;
  --gold-light: #f5e6c8;
  --rose-glow: rgba(251, 113, 133, 0.4);
  --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --app-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@supports not (height: 100dvh) {
  :root {
    --app-height: 100vh;
  }
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Montserrat', sans-serif;
  min-height: var(--app-height);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.touch-manipulation {
  touch-action: manipulation;
}

/* ===== Shell principal ===== */
.app-shell {
  min-height: var(--app-height);
  height: var(--app-height);
  width: 100%;
  overflow: hidden;
}

.safe-top-progress {
  padding-top: var(--safe-top);
}

/* ===== Pantallas ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(0.75rem + var(--safe-top))
    calc(0.75rem + var(--safe-right))
    calc(0.75rem + var(--safe-bottom))
    calc(0.75rem + var(--safe-left));
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.98);
  transition:
    opacity 0.7s var(--transition-smooth),
    transform 0.7s var(--transition-smooth),
    visibility 0.7s;
  pointer-events: none;
  overflow: hidden;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.screen.exit-left {
  transform: translateX(-40px) scale(0.97);
  opacity: 0;
}

/* Pantallas con scroll (galería) */
.screen.screen-scrollable {
  align-items: flex-start;
  justify-content: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.screen.screen-scrollable.active {
  transform: none;
}

.gallery-wrap {
  padding-top: 0.25rem;
}

/* ===== Tarjeta cristal ===== */
.card-glass {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.03) 100%
  );
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 1.25rem;
  box-shadow:
    0 20px 40px -12px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(251, 113, 133, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

@media (min-width: 640px) {
  .card-glass {
    border-radius: 1.5rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
}

/* ===== Divisor dorado ===== */
.divider-gold {
  width: 64px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

@media (min-width: 640px) {
  .divider-gold {
    width: 80px;
  }
}

/* ===== Botones ===== */
.btn-next {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  min-height: 48px;
  padding: 0.875rem 1.75rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-light);
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.2), rgba(212, 175, 55, 0.05));
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.btn-next-block {
  width: 100%;
  max-width: 280px;
}

.btn-next::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.3), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.btn-next:active {
  transform: scale(0.97);
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.35), rgba(212, 175, 55, 0.1));
  border-color: var(--gold);
}

@media (hover: hover) and (pointer: fine) {
  .btn-next:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(212, 175, 55, 0.25);
    border-color: var(--gold);
  }

  .btn-next:hover::before {
    opacity: 1;
  }
}

/* ===== Opciones de pregunta ===== */
.option-btn {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 52px;
  text-align: left;
  padding: 0.875rem 1rem;
  margin-bottom: 0.625rem;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9375rem;
  line-height: 1.35;
  font-weight: 400;
  color: rgba(255, 241, 242, 0.92);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.875rem;
  cursor: pointer;
  transition: all 0.25s ease;
  -webkit-user-select: none;
  user-select: none;
}

.option-btn:active {
  background: rgba(251, 113, 133, 0.22);
  border-color: rgba(251, 113, 133, 0.5);
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .option-btn:hover {
    background: rgba(251, 113, 133, 0.15);
    border-color: rgba(251, 113, 133, 0.4);
    transform: translateX(6px);
    box-shadow: -4px 0 20px rgba(251, 113, 133, 0.15);
  }
}

.option-btn:last-child {
  margin-bottom: 0;
}

/* ===== Marco de foto ===== */
.photo-frame {
  position: relative;
  padding: 8px;
  background: linear-gradient(145deg, #f5e6c8 0%, #d4af37 30%, #b8860b 60%, #d4af37 100%);
  border-radius: 4px;
  box-shadow:
    0 16px 32px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 2px 4px rgba(255, 255, 255, 0.3);
  transform-style: preserve-3d;
  transition: transform 0.5s var(--transition-smooth), box-shadow 0.5s ease;
}

@media (min-width: 640px) {
  .photo-frame {
    padding: 12px;
  }
}

.photo-frame::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
  z-index: 2;
}

.photo-frame-inner {
  overflow: hidden;
  position: relative;
  aspect-ratio: 3 / 4;
  background: rgba(0, 0, 0, 0.3);
}

@media (min-width: 640px) {
  .photo-frame-inner {
    aspect-ratio: 4 / 5;
  }
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 1;
  transition: transform 0.6s var(--transition-smooth);
}

.gallery-item {
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.7s ease, transform 0.7s var(--transition-smooth);
  -webkit-tap-highlight-color: transparent;
}

.screen[data-screen="gallery"].active .gallery-item {
  animation: galleryFadeIn 0.8s ease both;
}

.screen[data-screen="gallery"].active .gallery-item:nth-child(1) { animation-delay: 0.05s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(2) { animation-delay: 0.15s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(3) { animation-delay: 0.25s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(4) { animation-delay: 0.35s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(5) { animation-delay: 0.45s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(6) { animation-delay: 0.55s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(7) { animation-delay: 0.65s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(8) { animation-delay: 0.75s; }
.screen[data-screen="gallery"].active .gallery-item:nth-child(9) { animation-delay: 0.85s; }

@keyframes galleryFadeIn {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.gallery-item.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.gallery-item:active .photo-frame {
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .gallery-item:hover .photo-frame {
    transform: translateY(-6px);
    box-shadow:
      0 24px 48px rgba(0, 0, 0, 0.45),
      0 0 30px var(--rose-glow);
  }

  .gallery-item:hover .photo-frame img {
    transform: scale(1.05);
  }
}

.gallery-caption {
  margin-top: 1rem;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.45;
  opacity: 1;
  transform: translateY(0);
}

/* ===== Corazones flotantes ===== */
.hearts-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.heart-float {
  position: absolute;
  bottom: -40px;
  font-size: 0.85rem;
  opacity: 0;
  animation: floatHeart linear infinite;
  filter: drop-shadow(0 0 4px rgba(251, 113, 133, 0.4));
  will-change: transform, opacity;
}

@keyframes floatHeart {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg) scale(0.6);
    opacity: 0;
  }
  10% { opacity: 0.55; }
  90% { opacity: 0.35; }
  100% {
    transform: translateY(-110dvh) translateX(20px) rotate(360deg) scale(0.9);
    opacity: 0;
  }
}

/* ===== Estrellas ===== */
.stars-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: white;
  border-radius: 50%;
  animation: twinkle var(--duration, 3s) ease-in-out infinite;
  box-shadow: 0 0 4px 1px rgba(255, 255, 255, 0.5);
}

.star::after {
  content: '✦';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 6px;
  color: rgba(255, 255, 255, 0.35);
}

@keyframes twinkle {
  0%, 100% { opacity: 0.15; transform: scale(0.8); }
  50% { opacity: 0.85; transform: scale(1.1); }
}

/* ===== Animaciones entrada ===== */
.animate-fade-in {
  animation: fadeIn 1s ease forwards;
}

.animate-fade-in-delay {
  animation: fadeIn 1s ease 0.3s forwards;
  opacity: 0;
}

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

.heart-pulse {
  animation: heartPulse 1.5s ease-in-out infinite;
}

@keyframes heartPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(1rem + var(--safe-top))
    calc(1rem + var(--safe-right))
    calc(1rem + var(--safe-bottom))
    calc(1rem + var(--safe-left));
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 5, 20, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-content {
  position: relative;
  z-index: 1;
  animation: modalIn 0.45s var(--transition-smooth) forwards;
  -webkit-overflow-scrolling: touch;
}

.modal.show .modal-content {
  transform: scale(1);
  opacity: 1;
}

@keyframes modalIn {
  from {
    transform: scale(0.92) translateY(16px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 3, 15, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding:
    calc(0.75rem + var(--safe-top))
    calc(0.75rem + var(--safe-right))
    calc(0.5rem + var(--safe-bottom))
    calc(0.75rem + var(--safe-left));
}

.lightbox.hidden {
  display: none;
}

.lightbox-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 92vw;
  max-height: calc(var(--app-height) - 120px - var(--safe-top) - var(--safe-bottom));
  animation: lightboxIn 0.4s var(--transition-smooth);
  touch-action: pan-y;
}

@keyframes lightboxIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.lightbox-frame {
  width: 100%;
  max-width: min(420px, 92vw);
  margin: 0 auto;
}

.lightbox-image {
  max-height: min(52dvh, 420px);
  object-fit: contain;
  width: 100%;
}

.lightbox-swipe-hint {
  display: block;
}

@media (min-width: 768px) {
  .lightbox-swipe-hint {
    display: none;
  }

  .lightbox-image {
    max-height: 65dvh;
  }
}

.lightbox-close {
  position: absolute;
  top: calc(0.75rem + var(--safe-top));
  right: calc(0.75rem + var(--safe-right));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--gold-light);
  cursor: pointer;
  z-index: 3;
  transition: background 0.25s ease;
}

.lightbox-close:active {
  background: rgba(212, 175, 55, 0.25);
}

.lightbox-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  width: 100%;
  padding: 0.75rem 0 calc(0.5rem + var(--safe-bottom));
  flex-shrink: 0;
}

.lightbox-nav {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--gold-light);
  cursor: pointer;
  transition: background 0.25s ease;
  flex-shrink: 0;
}

.lightbox-nav:active {
  background: rgba(212, 175, 55, 0.25);
  transform: scale(0.95);
}

.lightbox-counter {
  min-width: 3.5rem;
  text-align: center;
}

@media (hover: hover) and (pointer: fine) {
  .lightbox-close:hover,
  .lightbox-nav:hover {
    background: rgba(212, 175, 55, 0.2);
    border-color: var(--gold);
  }
}

/* ===== Shimmer en marco ===== */
.photo-frame.shimmer::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.12),
    transparent
  );
  animation: shimmer 3.5s ease-in-out infinite;
  z-index: 3;
  pointer-events: none;
}

@keyframes shimmer {
  0% { left: -100%; }
  50%, 100% { left: 150%; }
}

/* ===== Pantallas pequeñas ===== */
@media (max-width: 380px) {
  .screen {
    padding:
      calc(0.5rem + var(--safe-top))
      calc(0.5rem + var(--safe-right))
      calc(0.5rem + var(--safe-bottom))
      calc(0.5rem + var(--safe-left));
  }

  .btn-next {
    font-size: 0.85rem;
    padding: 0.8rem 1.25rem;
  }

  .option-btn {
    font-size: 0.875rem;
    min-height: 48px;
  }
}

/* ===== Reducir animaciones ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .heart-float,
  .star {
    display: none;
  }
}

/* ===== Menos efectos en móvil para rendimiento ===== */
@media (max-width: 640px) {
  .card-glass {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .heart-float {
    animation-duration: 18s !important;
  }
}

/* ===== Panel diagnóstico (?debug=1) ===== */
.debug-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 3, 15, 0.96);
  overflow-y: auto;
  padding: 1rem;
  padding-top: calc(1rem + var(--safe-top));
}

.debug-panel.hidden {
  display: none;
}

.debug-panel-inner {
  max-width: 520px;
  margin: 0 auto;
  background: #2d1020;
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 1rem;
  padding: 1.25rem;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9rem;
}

.debug-panel-inner h2 {
  font-size: 1.1rem;
  color: #f5e6c8;
  margin: 0 0 0.75rem;
}

.debug-panel-inner ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.debug-panel-inner li {
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  line-height: 1.4;
  color: #fecdd3;
}

.debug-ok { color: #4ade80; font-weight: 600; }
.debug-fail { color: #f87171; font-weight: 600; }

.debug-panel-inner a {
  color: #fda4af;
  word-break: break-all;
}

.debug-tip {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  margin: 1rem 0;
  line-height: 1.5;
}
