/* ---------- Base & tokens ---------- */
:root {
  --bg-1: #0a2e33;
  --bg-2: #0f4c56;
  --pink: #ff8a65;
  --purple: #2fa2ab;
  --orange: #ffcf9e;
  --cream: #fff6ea;
  --ink: #123338;
  --accent: #ffd166;
  --shadow: rgba(8, 28, 32, 0.45);

  /* beach palette (part 2) */
  --beach-teal-deep: #0f4c56;
  --beach-teal: #1c7a84;
  --beach-teal-light: #2fa2ab;
  --beach-sand: #f3c7a6;
  --beach-sand-light: #fbe2cc;
  --beach-cream: #fff9f0;
  --beach-coral: #e2574c;
  --beach-ink: #123338;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-1);
  color: var(--cream);
  font-family: "Poppins", sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* evita el zoom amb doble toc sense bloquejar el pinch-zoom (accessibilitat) */
  touch-action: manipulation;
}

h1, h2, .title-hand {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  text-align: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a { font-family: inherit; }

/* visible, high-contrast focus ring for keyboard users */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

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

/* ---------- App shell ---------- */
.app {
  position: relative;
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 10%, rgba(47, 162, 171, 0.4), transparent 45%),
    radial-gradient(circle at 85% 20%, rgba(226, 87, 76, 0.3), transparent 50%),
    radial-gradient(circle at 50% 90%, rgba(255, 207, 158, 0.28), transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

.app::before {
  /* starfield */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.8;
  background-image:
    radial-gradient(2px 2px at 10% 20%, #fff, transparent),
    radial-gradient(2px 2px at 80% 15%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 40% 35%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 65% 60%, #fff, transparent),
    radial-gradient(2px 2px at 25% 75%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 90% 80%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 55% 10%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 15% 55%, #fff, transparent);
  background-size: 100% 100%;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  position: relative;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 100dvh;
  padding: 40px 24px 48px;
  text-align: center;
  z-index: 1;
}

.screen.is-active { display: flex; }

.screen[data-screen="part3"] {
  justify-content: center;
  overflow-y: auto;
}

/* Fons de fotos reals: la intro té la seva pròpia imatge; a partir de
   "Comença" (part1 oculta, part2, part3) es fa servir l'altra. */
.screen[data-screen="intro"] {
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.67) 0%, rgba(0, 0, 0, 0.67) 100%),
    url("../assets/graphics/bg-intro.jpg") lightgray 50% / cover no-repeat;
}

.screen[data-screen="part1"],
.screen[data-screen="part2"],
.screen[data-screen="part3"] {
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.67) 0%, rgba(0, 0, 0, 0.67) 100%),
    url("../assets/graphics/bg-main.jpg") lightgray 50% / cover no-repeat;
}

/* ---------- Intro ---------- */
.intro-content { max-width: 420px; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 8px;
}

.title-hand { font-size: clamp(36px, 10vw, 52px); margin-bottom: 32px; }

.intro-text {
  font-size: 16px;
  line-height: 1.5;
  color: rgba(255, 246, 234, 0.85);
  margin-bottom: 28px;
}

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: var(--ink);
  font-weight: 600;
  font-size: 16px;
  border: none;
  border-radius: 999px;
  padding: 14px 32px;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(255, 209, 102, 0.35);
  transition: transform 0.15s ease;
}

.btn-primary:active { transform: scale(0.96); }

/* ---------- Part header / dots ---------- */
.part-header {
  position: absolute;
  top: 24px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.part-kicker {
  font-family: "Fredoka", sans-serif;
  font-size: 22px;
  color: var(--accent);
  margin: 0;
}

.dots { display: flex; gap: 6px; }

.dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 246, 234, 0.25);
  transition: background 0.2s ease, transform 0.2s ease;
}

.dots .dot.is-done,
.dots .dot.is-current {
  background: var(--accent);
  transform: scale(1.2);
}

/* ---------- Collage stage ---------- */
.stage {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 489 / 621;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-step {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: sticker-drop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes sticker-drop {
  0% { opacity: 0; transform: translateY(-24px) rotate(var(--tilt, -3deg)) scale(0.92); }
  100% { opacity: 1; transform: translateY(0) rotate(var(--tilt, -3deg)) scale(1); }
}

.stage-photo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 14px 20px var(--shadow));
  rotate: var(--tilt, -3deg);
}

.step-caption {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(21px, 5.5vw, 26px);
  line-height: 1.25;
  color: var(--cream);
  background: rgba(10, 46, 51, 0.55);
  padding: 6px 18px;
  border-radius: 14px;
  max-width: 90%;
  min-height: 1.2em;
}

.tap-hint {
  display: inline-block;
  font-size: 14px;
  color: rgba(255, 246, 234, 0.7);
  letter-spacing: 0.04em;
  border-radius: 6px;
}

/* ---------- Finale (bubble heads + VR headset) ---------- */
.stage.is-finale {
  aspect-ratio: auto;
  max-width: 520px;
  height: auto;
}

.finale-heads {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  /* apareixen, les ulleres surten de seguida, es queden una bona estona
     posades, i després s'esvaeixen quan entra la imatge "monstre" */
  animation: heads-lifecycle 5.8s ease-out both;
}

@keyframes heads-lifecycle {
  0% { opacity: 0; }
  13.8% { opacity: 1; }
  86.2% { opacity: 1; }
  100% { opacity: 0; }
}

.finale-monster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  filter: drop-shadow(0 10px 16px var(--shadow));
  /* entra just quan els caps ja s'estan esvaint (veure heads-lifecycle) */
  animation: soft-fade-in 0.8s ease-out 5s both;
}

.head-slot {
  position: relative;
  width: 50%;
  flex-shrink: 0;
}

.head-slot.is-side { width: 42%; margin-bottom: 6%; }
.head-slot.is-side.is-left { margin-right: -17%; rotate: -6deg; }
.head-slot.is-side.is-right { margin-left: -17%; rotate: 6deg; z-index: 1; }
.head-slot.is-center { z-index: 2; }

.head-img {
  display: block;
  width: 100%;
  filter: drop-shadow(0 10px 16px var(--shadow));
}

.head-img.is-vr {
  position: absolute;
  inset: 0;
  opacity: 0;
  /* el retard (temps per veure els caps sense ulleres) es posa des del JS */
  animation: vr-fade 0.8s ease-in-out both;
}

@keyframes vr-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes soft-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.step-caption.is-finale-caption {
  font-size: clamp(22px, 6vw, 28px);
  color: var(--accent);
  background: transparent;
  padding: 0;
  /* apareix quan arriba el "monstre" (veure .finale-monster) */
  animation: soft-fade-in 0.8s ease-out 5s both;
}

/* el botó surt després del gag del "monstre", no abans */
.btn-gift {
  margin-top: 8px;
  animation: soft-fade-in 0.8s ease-out 6.6s both;
}

/* ---------- Part 2: birthday photo pile ---------- */
.screen[data-screen="part2"] {
  justify-content: space-between;
}

.bday-header {
  position: relative;
  z-index: 1;
  text-align: center;
}

.bday-title {
  font-size: clamp(38px, 10vw, 48px);
  color: var(--beach-cream);
  text-shadow: 0 4px 10px rgba(15, 76, 86, 0.4);
}

.bday-subtitle {
  margin: 6px 0 0;
  font-size: 15px;
  line-height: 1.5;
  color: rgba(255, 249, 240, 0.9);
  text-shadow: 0 2px 6px rgba(10, 46, 51, 0.8);
}

/* ocupa tota la pantalla: els stickers es reparteixen per tot el viewport */
.pile-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.pile-photo {
  position: absolute;
  width: clamp(170px, 56%, 300px);
  object-fit: contain;
  filter: drop-shadow(0 10px 16px rgba(15, 51, 56, 0.4));
  transform: translate(-50%, -50%) rotate(var(--pr, 0deg));
  /* apareix de cop, sense animació d'entrada */
  transition: filter 0.4s ease;
}

/* equivalent a una capa negra del 20 % (respecta la silueta del sticker) */
.pile-photo.is-old {
  filter: brightness(0.8) drop-shadow(0 10px 16px rgba(15, 51, 56, 0.4));
}

.bday-counter {
  position: relative;
  z-index: 1;
  font-family: "Fredoka", sans-serif;
  font-size: 34px;
  color: var(--beach-cream);
  background: rgba(10, 46, 51, 0.85);
  box-shadow: 0 8px 20px rgba(8, 28, 32, 0.35);
  padding: 2px 16px;
  border-radius: 999px;
  margin: 0;
  animation: counter-pulse 0.3s ease;
}

@keyframes counter-pulse {
  0% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* comptador a baix de tot, amb la pista (quan es veu) just a sobre */
.bday-footer {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.screen[data-screen="part2"] .tap-hint[hidden] { display: none; }

.bday-counter-total {
  font-size: 22px;
  opacity: 0.85;
}

.screen[data-screen="part2"] .tap-hint {
  position: relative;
  z-index: 1;
  color: var(--beach-cream);
  background: rgba(10, 46, 51, 0.85);
  padding: 4px 14px;
}

/* ---------- Part 3: caps + ulleres, després el regal ---------- */
.heads-reveal,
.envelope-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.heads-reveal[hidden],
.envelope-stage[hidden] {
  display: none;
}

/* ---------- Gift reveal (part 3): sobre ---------- */
.envelope-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  cursor: pointer;
  padding-top: 24px;
}

.envelope-label {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(24px, 6.5vw, 30px);
  font-weight: 600;
  line-height: 1.2;
  color: var(--cream);
  transition: opacity 0.4s ease;
}

.envelope {
  --paper: #f7efe2;
  --paper-mid: #efe2cd;
  --paper-dark: #e3d0b3;
  display: block;
  position: relative;
  width: min(280px, 78vw);
  aspect-ratio: 14 / 9;
  perspective: 900px;
  animation: envelope-float 3.2s ease-in-out infinite;
}

.envelope.is-open { animation: none; }

@keyframes envelope-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.envelope > span { position: absolute; display: block; }

/* interior del sobre (es veu quan s'obre la solapa) */
.envelope-back {
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #d9c3a2, var(--paper-dark));
  box-shadow: 0 24px 40px rgba(4, 20, 23, 0.45);
  z-index: 1;
}

/* la carta de dins: surt cap amunt en obrir-se */
.envelope-letter {
  left: 7%;
  right: 7%;
  top: 8%;
  height: 84%;
  border-radius: 6px;
  background:
    repeating-linear-gradient(180deg, transparent 0 17px, rgba(18, 51, 56, 0.07) 17px 18px),
    #fffdf8;
  box-shadow: 0 2px 6px rgba(18, 51, 56, 0.15);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10%;
  z-index: 2;
  transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.2, 1) 0.75s;
}

.envelope-letter-icon { font-size: 30px; }

/* part davantera: butxaca amb les solapes laterals i la inferior */
.envelope-pocket {
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(170deg, var(--paper), var(--paper-mid));
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  z-index: 3;
}

.envelope-pocket::before,
.envelope-pocket::after {
  content: "";
  position: absolute;
  inset: 0;
}

.envelope-pocket::before {
  background: linear-gradient(100deg, var(--paper-dark), var(--paper-mid));
  clip-path: polygon(0 0, 50% 56%, 0 100%);
}

.envelope-pocket::after {
  background: linear-gradient(260deg, var(--paper-dark), var(--paper-mid));
  clip-path: polygon(100% 0, 50% 56%, 100% 100%);
}

/* solapa superior: gira cap enrere en 3D i passa darrere la carta */
.envelope-flap {
  left: 0;
  right: 0;
  top: 0;
  height: 60%;
  background: linear-gradient(180deg, #fbf5ea, var(--paper-mid));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  filter: drop-shadow(0 3px 3px rgba(18, 51, 56, 0.18));
  z-index: 4;
  transition:
    transform 0.6s cubic-bezier(0.4, 0, 0.2, 1) 0.2s,
    z-index 0s linear 0.5s;
}

/* segell de cera */
.envelope-seal {
  left: 50%;
  top: 60%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  color: rgba(255, 240, 230, 0.92);
  background: radial-gradient(circle at 35% 30%, #f07a6c, var(--beach-coral) 55%, #b9372e);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.12),
    inset 0 -3px 6px rgba(0, 0, 0, 0.2),
    0 3px 6px rgba(18, 51, 56, 0.3);
  z-index: 5;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* seqüència d'obertura */
.envelope.is-open .envelope-seal { transform: scale(0.4); opacity: 0; }
.envelope.is-open .envelope-flap { transform: rotateX(180deg); z-index: 1; }
.envelope.is-open .envelope-letter { transform: translateY(-48%); }

.envelope-wrap.is-open .envelope-label,
.envelope-wrap.is-open .envelope-hint { opacity: 0; }

.envelope-hint { transition: opacity 0.3s ease; }

.gift-card {
  max-width: 420px;
  background: rgba(255, 246, 234, 0.08);
  border: 1px solid rgba(255, 246, 234, 0.18);
  border-radius: 20px;
  padding: 28px 24px;
  backdrop-filter: blur(6px);
  animation: sticker-drop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.gift-kicker {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 6px;
}

.gift-title {
  font-size: clamp(26px, 7vw, 32px);
  line-height: 1.15;
  margin-bottom: 16px;
}

.gift-facts {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  line-height: 1.4;
  color: rgba(255, 246, 234, 0.9);
}

.gift-desc {
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 246, 234, 0.85);
  margin-bottom: 22px;
}

.gift-map img {
  display: block;
  width: 100%;
  border-radius: 14px;
  filter: drop-shadow(0 8px 14px var(--shadow));
}

.gift-map-caption {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255, 246, 234, 0.8);
}

/* ---------- Responsive (tablet) ---------- */
@media (min-width: 600px) {
  .stage { max-width: 380px; }
}
