/* ============================================
   Dedica Digitale per Mary
   Mobile-first | iPhone 15 Pro Max target
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Palette */
  --color-bg: #F5F0EB;
  --color-bg-warm: #FBF7F2;
  --color-text: #2F2A28;
  --color-text-light: rgba(47, 42, 40, 0.72);
  --color-accent: #7FB3D3;        /* azzurro pietre/occhi */
  --color-accent-light: rgba(127, 179, 211, 0.3);
  --color-overlay: rgba(0, 0, 0, 0.25);

  /* Typography */
  --font-handwritten: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;

  /* Spacing — safe areas iOS */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Transitions */
  --transition-step: 800ms ease-in-out;
  --transition-text: 600ms ease-out;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* --- Step Container --- */
.step {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-step), visibility var(--transition-step);
  z-index: 0;
  padding: calc(var(--safe-top) + 24px) 32px calc(var(--safe-bottom) + 24px);
}

.step.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
}

/* --- Step Content --- */
.step-content {
  position: relative;
  z-index: 2;
  text-align: center;
  max-width: 380px;
}

.step-content--overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 48px 32px calc(var(--safe-bottom) + 48px);
  background: linear-gradient(to top, rgba(0,0,0,0.55) 0%, transparent 100%);
  z-index: 2;
  text-align: center;
  max-width: 100%;
  pointer-events: none;
}

.step-content--overlay .video-audio-prompt {
  pointer-events: auto;
}

.step-content--overlay-strong {
  padding-bottom: calc(var(--safe-bottom) + 56px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.76) 0%, rgba(0, 0, 0, 0.4) 45%, transparent 100%);
}

.step-content--overlay-step-3 {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  top: 0;
  bottom: 0;
  padding: calc(var(--safe-top) + 40px) 32px calc(var(--safe-bottom) + 40px);
  background: linear-gradient(180deg, rgba(14, 10, 9, 0.62) 0%, rgba(14, 10, 9, 0.5) 30%, rgba(14, 10, 9, 0.58) 100%);
}

/* --- Typography --- */
.handwritten-text {
  font-family: var(--font-handwritten);
  font-style: italic;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  line-height: 1.5;
  color: var(--color-text);
  --char-delay: 55ms;
  --char-initial-delay: 500ms;
  opacity: 0;
  animation: fadeInUp 1.2s ease-out 0.5s forwards;
}

/* Override quando JS attiva il character reveal */
.handwritten-text.char-reveal-active {
  opacity: 1;
  animation: none;
}

.handwritten-text[data-char-reveal-prepared="true"] {
  opacity: 1;
  animation: none;
}

.step-text {
  font-family: var(--font-handwritten);
  font-style: italic;
  font-size: clamp(1.2rem, 4.5vw, 1.8rem);
  line-height: 1.6;
  color: white;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.68), 0 0 24px rgba(0, 0, 0, 0.28);
  opacity: 0;
}

.step-2 .step-text {
  font-size: clamp(1.28rem, 4.9vw, 1.95rem);
}

.step.active .step-text {
  animation: fadeInUp 0.8s ease-out 0.3s forwards;
}

.step-text--large {
  font-size: clamp(1.4rem, 5.5vw, 2.2rem);
  color: var(--color-text);
  text-shadow: none;
  --char-delay: 40ms;
  --char-initial-delay: 300ms;
}

.step-text--large.char-reveal-active {
  opacity: 1;
  animation: none;
}

.step-text--large[data-char-reveal-prepared="true"] {
  opacity: 1;
  animation: none;
}

/* --- Backgrounds --- */
.step-bg {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.step-bg img,
.step-bg video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transition: opacity 400ms ease;
}

.step-bg.media-ready img,
.step-bg.media-ready video {
  opacity: 1;
}

/* Step 2: blur → focus effect */
.step-2 .step-bg img {
  filter: blur(8px);
  transform: scale(1.05);
  transition: opacity 400ms ease, filter 2s ease-out, transform 2s ease-out;
}

.step-2.active .step-bg img {
  filter: blur(0);
  transform: scale(1);
}

/* --- Placeholders (dev only) --- */
.placeholder-image,
.placeholder-video {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--color-text-light);
  background: linear-gradient(135deg, #e8e0d8 0%, #d4ccc4 100%);
}

.placeholder-video {
  background: linear-gradient(135deg, #d0c8c0 0%, #b8b0a8 100%);
}

.step-bg.media-visible .placeholder-image,
.step-bg.media-visible .placeholder-video {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 250ms ease, visibility 250ms ease;
}

.video-audio-prompt {
  position: relative;
  z-index: 4;
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  background: rgba(251, 247, 242, 0.88);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease, transform 220ms ease;
}

.video-step-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 18px);
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.video-step-nav-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(251, 247, 242, 0.9);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.video-step-progress {
  position: relative;
  flex: 1;
  max-width: 88px;
  height: 2px;
  border-radius: 999px;
  background: rgba(251, 247, 242, 0.32);
  overflow: hidden;
}

.video-step-progress-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: rgba(251, 247, 242, 0.78);
  transition: width 120ms linear;
}

.video-step-nav-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.video-step-nav-button--prev {
  justify-self: start;
  opacity: 0.92;
}

.video-step-nav-button--next {
  justify-self: end;
}

.video-audio-prompt:hover {
  background: rgba(251, 247, 242, 0.94);
}

.video-audio-prompt:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.step.active.video-needs-audio .step-bg.media-ready .video-audio-prompt,
.step-3.active:not(.video-started) .video-audio-prompt {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.step-3 .step-text {
  font-size: clamp(1.38rem, 5.2vw, 2.08rem);
}

.step-3-intro {
  transition: opacity 360ms ease, visibility 360ms ease;
}

.step-3.video-started .step-3-intro {
  opacity: 0;
  visibility: hidden;
}

.step-3 .step-bg {
  background: #564640;
}

.step-3 .step-bg video {
  transition: opacity 500ms ease;
}

.step-3 .step-bg.media-ready video {
  opacity: 0;
}

.step-3.video-started .step-bg.media-ready video {
  opacity: 1;
}

.step-3 .step-bg.media-visible .placeholder-video {
  opacity: 1;
  visibility: visible;
  pointer-events: none;
}

.step-3.video-started .step-bg.media-visible .placeholder-video {
  opacity: 0;
  visibility: hidden;
}

.step-3 .video-audio-prompt {
  min-width: 220px;
  padding: 14px 24px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  background: rgba(251, 247, 242, 0.92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.step-3.video-can-unmute .video-audio-prompt {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.step-3.video-started .video-audio-prompt {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.step-3.video-started .video-step-controls,
.step-5.video-started .video-step-controls {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.step-content--overlay-step-5 {
  display: flex;
  align-items: center;
  justify-content: center;
  top: 0;
  bottom: 0;
  padding: calc(var(--safe-top) + 40px) 32px calc(var(--safe-bottom) + 40px);
  background: linear-gradient(180deg, rgba(32, 24, 22, 0.5) 0%, rgba(32, 24, 22, 0.38) 35%, rgba(32, 24, 22, 0.5) 100%);
}

.step-5-intro {
  transition: opacity 360ms ease, visibility 360ms ease;
}

.step-5.video-started .step-5-intro {
  opacity: 0;
  visibility: hidden;
}

.step-5 .step-bg {
  background: #6a5b54;
}

.step-5 .step-bg.media-ready video {
  opacity: 0;
}

.step-5.video-started .step-bg.media-ready video {
  opacity: 1;
}

.step-5 .step-bg.media-visible .placeholder-video {
  opacity: 1;
  visibility: visible;
  pointer-events: none;
}

.step-5.video-started .step-bg.media-visible .placeholder-video {
  opacity: 0;
  visibility: hidden;
}

.step-5 .video-audio-prompt {
  min-width: 220px;
  max-width: 300px;
  padding: 14px 24px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(251, 247, 242, 0.92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.step-5.active:not(.video-started) .video-audio-prompt {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.step-5.video-started .video-audio-prompt {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.step.active .step-bg.media-ready.video-needs-audio .video-audio-prompt:active,
.step-3.video-can-unmute .video-audio-prompt:active,
.step-5.video-can-unmute .video-audio-prompt:active {
  transform: scale(0.98);
}

/* --- Step-specific styles --- */

/* Step 1: sfondo caldo */
.step-1 {
  background-color: var(--color-bg-warm);
}

/* Step 4: sfondo caldo (eventuale sfondo Nano Banana via background-image) */
.step-4 {
  background-color: var(--color-bg-warm);
}

.step-4 .step-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(251, 247, 242, 0.5) 0%, rgba(251, 247, 242, 0.68) 100%);
}

.step-4 .step-content {
  position: relative;
  z-index: 2;
}

.step-4 .step-text--large {
  color: #2f2a28;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 24px rgba(255, 255, 255, 0.2);
}

/* Step 6: sfondo per particelle */
.step-6 {
  background-color: var(--color-bg-warm);
}

#particles-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* --- Timeline (Step 6) --- */
.timeline {
  position: relative;
  z-index: 2;
  margin-bottom: 48px;
}

.timeline-item {
  opacity: 0;
  margin-bottom: 20px;
}

.step-6.active .timeline-item {
  animation: fadeInUp 0.6s ease-out forwards;
}

.step-6.active .timeline-item:nth-child(1) { animation-delay: 0.3s; }
.step-6.active .timeline-item:nth-child(2) { animation-delay: 0.7s; }
.step-6.active .timeline-item:nth-child(3) { animation-delay: 1.1s; }
.step-6.active .timeline-item:nth-child(4) { animation-delay: 1.5s; }

.timeline-date {
  font-family: var(--font-handwritten);
  font-size: clamp(1.34rem, 4.9vw, 1.86rem);
  color: var(--color-text);
  letter-spacing: 0.02em;
}

.closing-signature {
  font-family: var(--font-handwritten);
  font-style: italic;
  font-size: clamp(1.66rem, 5.9vw, 2.34rem);
  color: var(--color-text-light);
  --char-delay: 60ms;
  --char-initial-delay: 2200ms;
  opacity: 0;
}

.step-6.active .closing-signature {
  animation: fadeInUp 0.6s ease-out 2.2s forwards;
}

.closing-signature.char-reveal-active {
  opacity: 1;
  animation: none;
}

.closing-signature[data-char-reveal-prepared="true"] {
  opacity: 1;
  animation: none;
}

/* --- Tap Indicator (Step 1) --- */
.tap-indicator {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 26px);
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
}

.step-1.active .tap-indicator {
  animation: fadeIn 1s ease-out 3.2s forwards;
}

.tap-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(47, 42, 40, 0.72);
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

/* --- Character Reveal Animation --- */
.char {
  display: inline-block;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.char-reveal-active .char {
  opacity: 1;
  transform: translateY(0);
  transition-delay: calc(var(--i) * var(--char-delay, 55ms) + var(--char-initial-delay, 500ms));
}

.char--space {
  width: 0.3em;
}

.word {
  display: inline-block;
  white-space: nowrap;
}

/* Cursore scrittura */
.char-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background-color: currentColor;
  margin-left: 1px;
  vertical-align: baseline;
  opacity: 0;
}

.char-cursor.active {
  animation: cursorBlink 0.6s ease-in-out infinite;
}

.char-cursor.done {
  animation: cursorFadeOut 0.5s ease-out forwards;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes cursorFadeOut {
  to { opacity: 0; }
}
