*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ivory: #F7F3EA;
  --cream: #EFE8DA;
  --papel: #FFFcf7;
  --olive: #5C6448;
  --olive-deep: #3E4532;
  --olive-soft: #7A8466;
  --ink: #2C2B26;
  --muted: #6B675C;
  --soft: #9A968A;
  --line: rgba(92, 100, 72, 0.22);
  --serif: 'Antic Didone', 'Cormorant Garamond', Georgia, serif;
  --script: 'Pinyon Script', cursive;
  --sans: 'Manrope', system-ui, sans-serif;
  --safe: env(safe-area-inset-bottom, 0px);
}

html {
  min-height: 100%;
  background-color: #EDE6D8;
}

html, body {
  overflow-x: hidden;
  width: 100%;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

body {
  position: relative;
  padding-bottom: 40px;
  background-color: #EDE6D8;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(92, 100, 72, 0.022) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 65%, rgba(92, 100, 72, 0.018) 0 1px, transparent 1px),
    linear-gradient(180deg, var(--ivory) 0%, var(--cream) 55%, var(--ivory) 100%);
  background-size: 150px 150px, 150px 150px, auto;
}

button {
  font-family: var(--sans);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:focus { outline: none; }
button:focus-visible { outline: 1px solid var(--olive-soft); outline-offset: 3px; }

/* ---------- Header ---------- */
.page-top {
  text-align: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 16px 8px;
  position: relative;
  z-index: 2;
}

.back-link {
  display: inline-block;
  font-family: var(--sans);
  font-weight: 300;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--soft);
  text-decoration: none;
  margin-bottom: 16px;
  transition: color 0.25s;
}
.back-link:hover { color: var(--olive); }

.page-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(28px, 7.2vw, 40px);
  color: var(--olive-deep);
  line-height: 1.15;
  margin-bottom: 10px;
}

.page-sub {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(13px, 3.2vw, 15px);
  color: var(--muted);
  max-width: 360px;
  margin: 0 auto;
  line-height: 1.55;
}

/* ---------- Sobre + hoja (como Daniela) ---------- */
.upload-carta {
  padding: 12px 16px 0;
  position: relative;
  z-index: 1;
  margin-bottom: clamp(-40px, -8vw, -24px);
}

.inv-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: clamp(560px, 148vw, 680px);
  overflow: visible;
}

@media (max-width: 480px) {
  .inv-container { min-height: 128vw; }
}

.layer {
  position: absolute;
  width: 100%;
  height: auto;
  top: 0;
  left: 0;
  pointer-events: none;
  user-select: none;
}

.z1 {
  z-index: 1;
  filter: saturate(0.55);
}

.inv-sello {
  width: 14%;
  left: 43%;
  top: 19%;
  z-index: 10;
  filter: drop-shadow(0 5px 11px rgba(62, 69, 50, 0.26));
  animation: sello-pulse 4.2s ease-in-out infinite;
}

@keyframes sello-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.paper-wrapper {
  position: absolute;
  top: 23.5%;
  left: 50%;
  width: 86%;
  transform: translateX(-50%);
  z-index: 5;
}

.inv-paper {
  width: 100%;
  min-height: clamp(340px, 88vw, 420px);
  background-color: var(--papel);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(92, 100, 72, 0.02) 0 1px, transparent 1px),
    radial-gradient(ellipse at 50% 22%, #FFFFFF, var(--ivory) 78%);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(62, 69, 50, 0.12);
  padding: clamp(18px, 4.5vw, 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.inv-paper::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(92, 100, 72, 0.13);
  pointer-events: none;
}

.inv-paper-inner {
  width: 100%;
  max-width: 300px;
  position: relative;
  z-index: 1;
  transform: translateY(clamp(-18px, -4.5vw, -12px));
}

.upload-names {
  font-family: var(--script);
  font-size: clamp(24px, 6.4vw, 34px);
  color: var(--olive-deep);
  margin-bottom: 12px;
  line-height: 1.15;
}

.upload-desc {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(12px, 2.9vw, 14px);
  line-height: 1.65;
  color: var(--muted);
  margin-bottom: 18px;
}

.upload-wrapper {
  width: 100%;
  padding: 8px 4px 4px;
  text-align: center;
}

.upload-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.btn-subir-fotos {
  display: inline-block;
  width: 100%;
  max-width: 280px;
  padding: 13px 20px;
  background: var(--olive);
  color: var(--ivory);
  border: 1.5px solid var(--olive);
  border-radius: 0;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.25s, transform 0.2s, color 0.25s, opacity 0.25s;
}

.btn-subir-fotos--sec {
  background: transparent;
  color: var(--olive-deep);
  box-shadow: none;
}

.btn-subir-fotos:hover {
  background: var(--olive-deep);
  color: var(--ivory);
  transform: translateY(-1px);
}

.btn-subir-fotos--sec:hover {
  background: rgba(92, 100, 72, 0.08);
  color: var(--olive-deep);
}

.btn-subir-fotos:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.upload-hint {
  font-family: var(--sans);
  font-weight: 300;
  font-size: 11px;
  line-height: 1.55;
  color: var(--soft);
  margin-top: 12px;
  padding: 0 6px;
}
.upload-hint.ok { color: var(--olive); }
.upload-hint.err { color: #97563F; }

/* ---------- Cue de scroll ---------- */
.scroll-cue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 320px;
  margin: clamp(10px, 3vw, 18px) auto 0;
  padding: 0 16px 8px;
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  z-index: 4;
  -webkit-tap-highlight-color: transparent;
}

.scroll-cue-text {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(12px, 3vw, 14px);
  color: var(--olive);
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.scroll-cue-arrow {
  font-size: 18px;
  color: var(--olive-soft);
  line-height: 1;
  animation: scroll-flecha 1.6s ease-in-out infinite;
}

@keyframes scroll-flecha {
  0%, 100% { transform: translateY(0); opacity: 0.75; }
  50% { transform: translateY(5px); opacity: 1; }
}

/* ---------- Galería ---------- */
.gallery-section {
  max-width: 520px;
  margin: clamp(-12px, -3vw, -4px) auto 0;
  padding: 0 12px calc(24px + var(--safe));
  text-align: center;
  position: relative;
  z-index: 2;
  transition: opacity 0.45s ease;
}

.gallery-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(26px, 6.5vw, 34px);
  color: var(--olive-deep);
  margin-bottom: 8px;
}

.gallery-hashtag {
  font-family: var(--sans);
  font-weight: 300;
  font-size: clamp(12px, 3.2vw, 14px);
  letter-spacing: 0.16em;
  color: var(--olive);
  margin-bottom: 18px;
}

.mosaico-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 10px;
  padding: 8px 6px 12px;
  min-height: 100px;
  max-height: calc(3 * (min(148px, 28vw) + 2.75rem) + 2 * 14px + 0.5rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  align-items: start;
  justify-items: center;
  scrollbar-width: thin;
  scrollbar-color: rgba(92, 100, 72, 0.4) transparent;
}

.mosaico-grid::-webkit-scrollbar { width: 5px; }
.mosaico-grid::-webkit-scrollbar-thumb {
  background: rgba(92, 100, 72, 0.35);
  border-radius: 999px;
}

#status-msg {
  grid-column: 1 / -1;
  font-family: var(--sans);
  font-weight: 300;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--soft);
  padding: 24px 8px;
}

.polaroid-item {
  width: 100%;
  max-width: 148px;
  background: #fff;
  padding: 7px 7px 22px;
  box-shadow:
    0 3px 10px rgba(62, 69, 50, 0.12),
    0 8px 22px rgba(62, 69, 50, 0.08);
  cursor: pointer;
  transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0px));
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease;
  position: relative;
  z-index: 1;
  will-change: transform;
}

.polaroid-item img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--cream);
}

.polaroid-item:hover {
  z-index: 5;
  box-shadow:
    0 6px 16px rgba(62, 69, 50, 0.16),
    0 14px 28px rgba(62, 69, 50, 0.1);
  transform: rotate(var(--rot, 0deg)) translateY(calc(var(--ty, 0px) - 3px)) scale(1.04);
}

.polaroid-item.is-new {
  animation: polaroidEnter 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
  z-index: 6;
}

.polaroid-item.is-shift {
  animation: polaroidShift 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes polaroidEnter {
  from {
    opacity: 0;
    transform: translateX(-36px) rotate(calc(var(--rot, 0deg) - 4deg)) scale(0.88);
  }
  to {
    opacity: 1;
    transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0px)) scale(1);
  }
}

@keyframes polaroidShift {
  0% { transform: translateX(-32px) rotate(var(--rot, 0deg)) translateY(var(--ty, 0px)); }
  45% { transform: translateX(16px) rotate(var(--rot, 0deg)) translateY(var(--ty, 0px)); }
  100% { transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0px)); }
}

.btn-refrescar {
  display: inline-block;
  margin-top: 14px;
  padding: 8px 18px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 300;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
}
.btn-refrescar:hover { background: rgba(92, 100, 72, 0.06); }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  z-index: 9999;
  inset: 0;
  background: rgba(30, 29, 25, 0.9);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  padding: 16px;
}

.modal-content-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  text-align: center;
}

#modal-img {
  max-width: 100%;
  max-height: 68vh;
  border: 1px solid rgba(255, 252, 247, 0.2);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.modal-controls {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-nav, .btn-download {
  display: inline-block;
  padding: 11px 20px;
  background: transparent;
  color: var(--papel);
  border: 1.5px solid rgba(255, 252, 247, 0.55);
  font-family: var(--sans);
  font-weight: 300;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.25s, color 0.25s;
}

.btn-nav:hover, .btn-download:hover {
  background: var(--papel);
  color: var(--olive-deep);
}

.btn-download {
  background: var(--papel);
  color: var(--olive-deep);
  border-color: var(--papel);
}
.btn-download:disabled { opacity: 0.55; cursor: wait; }

.modal-close {
  position: absolute;
  top: -44px;
  right: 0;
  color: var(--papel);
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px 8px;
  opacity: 0.85;
}
.modal-close:hover { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .inv-sello,
  .scroll-cue-arrow,
  .polaroid-item.is-new,
  .polaroid-item.is-shift { animation: none; }
}
