/* ===============================
   Global reset & base
   =============================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
}

/* ===============================
   Reduced motion support - ENHANCED
   =============================== */

@media (prefers-reduced-motion: reduce) {
  /* Keep only opacity transitions, remove all transforms */
  .slide {
    transform: none !important;
  }
  
  .slide[data-chapter] {
    transition: opacity 0.3s ease !important;
    transform: none !important;
  }
  
  .slide[data-chapter].visible {
    transform: none !important;
  }
  
  /* Disable all other animations */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  
  /* Keep essential fades only */
  .title,
  .caption,
  .overlay-text,
  .overlay-dim {
    transition: opacity 0.3s ease !important;
  }
}

/* ===============================
   Body & background
   =============================== */

body {
  background-color: #0a0a0a;
  color: #e5e5e5;

  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;

  overflow: hidden;
}

/* ===============================
   App container
   =============================== */

#app {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ===============================
   Loading state
   =============================== */

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0a0a0a;
  z-index: 100;
  opacity: 1;
  transition: opacity 1s ease;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 3vw, 24px);
  color: #e5e5e5;
  opacity: 0.7;
  letter-spacing: 0.05em;
}

/* ===============================
   Renderer stage
   =============================== */

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ===============================
   Slide (image layer) - BASE
   =============================== */

.slide {
  position: absolute;
  inset: 0;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0;
  transform: scale(1);
  will-change: opacity, transform;
}

/* Vignette effect for nostalgia */
.slide::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 0%,
    transparent 40%,
    rgba(0, 0, 0, 0.15) 80%,
    rgba(0, 0, 0, 0.3) 100%
  );
  pointer-events: none;
}

/* ===============================
   TRANSITION STYLES - Chapter-Aware
   =============================== */

/* WELCOME - Slow zoom with fade */
.slide[data-chapter="welcome"] {
  transition: opacity 1.5s ease, transform 1.5s ease;
}
.slide[data-chapter="welcome"].visible {
  opacity: 1;
  transform: scale(1.02);
}

/* ARRIVING - Gentle upward float */
.slide[data-chapter="arriving"] {
  transform: translateY(20px) scale(1);
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.slide[data-chapter="arriving"].visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* OLD BONDS - Slight rotation with fade */
.slide[data-chapter="old-bonds"] {
  transform: scale(1) rotate(-1deg);
  transition: opacity 1s ease, transform 1s ease;
}
.slide[data-chapter="old-bonds"].visible {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* SHARING - Dynamic crossfade with subtle rotation */
.slide[data-chapter="sharing"] {
  transform: scale(0.98) rotate(1deg);
  transition: opacity 1s ease, transform 1s ease;
}
.slide[data-chapter="sharing"].visible {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* WAITING HOTEL - Standard smooth fade */
.slide[data-chapter="waiting-hotel"] {
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.slide[data-chapter="waiting-hotel"].visible {
  opacity: 1;
  transform: scale(1);
}

/* CAKE - Emotional moment, slow and gentle */
.slide[data-chapter="cake"] {
  transition: opacity 1.4s ease, transform 1.4s ease;
}
.slide[data-chapter="cake"].visible {
  opacity: 1;
  transform: scale(1.01);
}

/* HUMOR WAITING - Quick slide-in from right */
.slide[data-chapter="humor-waiting"] {
  transform: translateX(30px) scale(0.98);
  transition: opacity 0.7s cubic-bezier(0.34, 1.56, 0.64, 1), 
              transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.slide[data-chapter="humor-waiting"].visible {
  opacity: 1;
  transform: translateX(0) scale(1);
}

/* SHE ARRIVED - Emotional entrance, slow reveal */
.slide[data-chapter="she-arrived"] {
  transform: scale(0.95);
  transition: opacity 1.5s ease, transform 1.5s ease;
}
.slide[data-chapter="she-arrived"].visible {
  opacity: 1;
  transform: scale(1);
}

/* LUNCH - Standard smooth */
.slide[data-chapter="lunch"] {
  transition: opacity 1s ease, transform 1s ease;
}
.slide[data-chapter="lunch"].visible {
  opacity: 1;
  transform: scale(1);
}

/* UNHURRIED - Gentle fade with slight zoom */
.slide[data-chapter="unhurried"] {
  transform: scale(0.98);
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.slide[data-chapter="unhurried"].visible {
  opacity: 1;
  transform: scale(1);
}

/* GOODBYE - Scale down with fade for closure */
.slide[data-chapter="goodbye"] {
  transform: scale(1.03);
  transition: opacity 2s ease, transform 2s ease;
}
.slide[data-chapter="goodbye"].visible {
  opacity: 1;
  transform: scale(1);
}

/* GRATITUDE - Slow reverent zoom */
.slide[data-chapter="gratitude"] {
  transform: scale(0.95);
  transition: opacity 1.5s ease, transform 1.5s ease;
}
.slide[data-chapter="gratitude"].visible {
  opacity: 1;
  transform: scale(1.03);
}

/* ===============================
   Chapter title
   =============================== */

.title {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);

  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: clamp(24px, 4vw, 36px);
  font-weight: 400;
  letter-spacing: 0.03em;

  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
  
  /* Better readability */
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

/* ===============================
   Caption (humor only)
   =============================== */

.caption {
  position: absolute;
  left: 50%;
  bottom: 10%;
  transform: translateX(-50%);

  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 2.5vw, 22px);
  font-weight: 400;
  letter-spacing: 0.02em;

  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  
  /* Better readability */
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

/* ===============================
   Overlay (Gratitude Spotlight)
   =============================== */

.overlay-dim {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.overlay-hole {
  position: absolute;
  border-radius: 50%;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.7),
    inset 0 0 50px rgba(255, 255, 255, 0.1);
  transition: all 0.5s ease;
}

/* ===============================
   Overlay text
   =============================== */

.overlay-text {
  position: absolute;
  color: #e5e5e5;

  font-family: ui-serif, Georgia, "Times New Roman", serif;
  line-height: 1.5;

  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
  
  /* Enhanced readability for older audience */
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.9);
  font-weight: 400;
}

/* ===============================
   End Card
   =============================== */

.end-card {
  position: absolute;
  inset: 0;
  background-color: #0a0a0a;

  display: flex;
  align-items: center;
  justify-content: center;

  opacity: 0;
  transition: opacity 1.5s ease;
}

.end-card.visible {
  opacity: 1;
}

.end-card-text {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: clamp(22px, 3.5vw, 32px);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: #e5e5e5;
  opacity: 0.9;
  text-align: center;
  padding: 0 20px;
  max-width: 600px;
}

/* ===============================
   Controls - Enhanced for accessibility
   =============================== */

.controls {
  position: fixed;
  right: 20px;
  bottom: 20px;

  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 400px;
  justify-content: flex-end;

  opacity: 1;
  transition: opacity 0.4s ease;
  z-index: 10;
}

.controls.hidden {
  opacity: 0;
  pointer-events: none;
}

.controls button {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: #e5e5e5;

  /* Larger touch targets for 45-55 age group */
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;

  font-size: 22px;
  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;

  transition: all 0.3s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.controls button:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.05);
}

.controls button:active {
  transform: scale(0.95);
}

/* Special styling for restart button */
#restartBtn {
  font-size: 24px;
  font-weight: 500;
}

/* ===============================
   Mobile optimizations
   =============================== */

@media (max-width: 768px) {
  .title {
    bottom: 15%;
    font-size: clamp(20px, 5vw, 28px);
  }

  .caption {
    bottom: 8%;
    font-size: clamp(14px, 3.5vw, 18px);
  }

  .controls {
    right: 12px;
    bottom: 12px;
    gap: 10px;
    max-width: calc(100vw - 24px);
  }

  .controls button {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    font-size: 20px;
  }

  #restartBtn {
    font-size: 22px;
  }

  .overlay-text {
    line-height: 1.4;
  }
}

/* ===============================
   Tablet landscape
   =============================== */

@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
  .title {
    bottom: 12%;
  }

  .caption {
    bottom: 6%;
  }
}

/* ===============================
   Fullscreen toast notification
   =============================== */

.fullscreen-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  
  padding: 12px 24px;
  
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: 16px;
  color: #e5e5e5;
  
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 1000;
}

.fullscreen-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 768px) {
  .fullscreen-toast {
    font-size: 14px;
    padding: 10px 20px;
  }
}