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

:root {
  --bg: #C1D1D0;
  --sage: #6B7F78;
  --dusty-rose: #B5696C;
  --dark-slate: #33403E; /* used for text */
}

body {
  font-family: 'Montserrat', sans-serif;
  background-color: var(--bg);
  color: var(--dark-slate);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Password Gate ── */
#gate {
  text-align: center;
  padding: 2rem;
  max-width: 420px;
  width: 100%;
}

#gate h1 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 400;
  font-size: 3rem;
  color: var(--dark-slate);
  margin-bottom: 0.25rem;
  letter-spacing: 0.04em;
}

#gate .ampersand {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  color: var(--dusty-rose);
  font-size: 2rem;
  display: block;
  margin: -0.25rem 0;
}

#gate p {
  font-weight: 300;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sage);
  margin: 1.5rem 0 2rem;
}

#gate .hint {
  font-weight: 300;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--dusty-rose);
  margin-top: 0.25rem;
}

#gate form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

#gate .input-wrapper {
  position: relative;
  width: 100%;
  max-width: 280px;
}

#gate .input-wrapper input {
  width: 100%;
}

#gate #toggle-visibility {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--sage);
  transition: color 0.3s;
}

#gate #toggle-visibility:hover {
  color: var(--dusty-rose);
}

#gate input[type="password"],
#gate input[type="text"] {
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  font-weight: 300;
  text-align: center;
  letter-spacing: 0.1em;
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--sage);
  border-radius: 0;
  background: transparent;
  color: var(--dark-slate);
  width: 100%;
  max-width: 280px;
  outline: none;
  transition: border-color 0.3s;
}

#gate input[type="password"]:focus,
#gate input[type="text"]:focus {
  border-color: var(--dusty-rose);
}

#gate input[type="password"]::placeholder,
#gate input[type="text"]::placeholder {
  color: var(--sage);
  font-weight: 300;
}

#gate button[type="submit"] {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 0.7rem 2.5rem;
  border: 1px solid var(--dusty-rose);
  background: transparent;
  color: var(--dusty-rose);
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s;
}

#gate button:hover {
  background-color: var(--dusty-rose);
  color: var(--bg);
}

.error-msg {
  font-size: 0.8rem;
  color: var(--sage);
  margin-top: 0.25rem;
  min-height: 1.2em;
}

/* ── App Shell (post-auth) ── */
#app {
  display: none;
  width: 100%;
  min-height: 100vh;
}

#app.visible {
  display: flex;
}

/* ── Side Navigation ── */
.side-nav {
  width: 220px;
  min-height: 100vh;
  border-right: 1px solid rgba(107, 127, 120, 0.2);
  padding: 2rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  background: var(--bg);
  z-index: 10;
}

.side-nav .nav-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.1rem;
  color: var(--dark-slate);
  margin-bottom: 2rem;
  text-align: center;
  line-height: 1.3;
}

.side-nav .nav-logo .amp {
  font-style: italic;
  color: var(--dusty-rose);
  font-size: 0.9rem;
}

.side-nav a {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  letter-spacing: 0.03em;
  color: var(--sage);
  text-decoration: none;
  padding: 0.9rem 1.25rem 0.9rem 1.25rem;
  white-space: normal;
  overflow-wrap: break-word;
  line-height: 1.3;
  width: calc(100% - 20px);
  box-sizing: border-box;
  text-align: center;
  cursor: pointer;
  border-right: 2.5px solid transparent;
  transition: color 0.3s, border-color 0.3s;
}

.side-nav a.active {
  color: var(--dusty-rose);
  border-right-color: var(--dusty-rose);
  background: transparent;
}

.side-nav a:hover {
  color: var(--dusty-rose);
}

/* ── Main Content Area ── */
.main-content {
  flex: 1;
  margin-left: 220px;
  min-height: 100vh;
}

/* ── Page: Home ── */
.page-home {
  text-align: center;
  position: relative;
  z-index: 1;
  padding: 2rem 0 2rem 2rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.page-home .home-spacer {
  flex: 0 1 10%;
}

.page-home .text-content {
  flex: 1 1 35%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.page-home .hero-image {
  flex: 0 1 40%;
  max-width: 600px;
  overflow: hidden;
}

.page-home .hero-image img {
  width: 100%;
  height: auto;
  display: block;
}

.page-home h1 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 400;
  font-size: 3.2rem;
  color: var(--dark-slate);
  margin-bottom: 0.15rem;
  letter-spacing: 0.04em;
}

.page-home .ampersand {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  color: var(--dusty-rose);
  font-size: 2.2rem;
  display: block;
  margin: -0.2rem 0;
}

.page-home .divider {
  width: 60px;
  height: 1px;
  background-color: var(--dusty-rose);
  margin: 1.5rem auto;
}

.page-home .message {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 1.6rem;
  line-height: 1.8;
  color: var(--dark-slate);
  letter-spacing: 0.03em;
}

.page-home .details {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 1.3rem;
  line-height: 1.8;
  color: var(--dark-slate);
  letter-spacing: 0.06em;
}

.page-home .subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.15rem;
  color: var(--sage);
  margin-top: 0.5rem;
}

/* ── Page: Our Story ── */
.page-our-story {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 2rem;
  position: relative;
  outline: none;
}

.page-our-story h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 400;
  font-size: 2rem;
  color: var(--dark-slate);
  text-align: center;
  margin-bottom: 0.5rem;
}

.page-our-story .story-instructions {
  text-align: center;
  font-size: 0.75rem;
  color: var(--sage);
  letter-spacing: 0.05em;
  margin-bottom: 2rem;
}

/* Timeline viewport — clips the scrolling world */
.timeline-viewport {
  flex: 1;
  position: relative;
  min-height: 400px;
  width: 100%;
  overflow: hidden;
}

/* Wide world — absolutely positioned, moved via transform */
.timeline-world {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
}

.timeline-line {
  position: absolute;
  top: 80%;
  left: 0;
  height: 2px;
  background: var(--dusty-rose);
}

.timeline-dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: var(--dusty-rose);
  border-radius: 50%;
  z-index: 2;
  transition: opacity 0.4s ease;
}

.timeline-label {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  color: var(--sage);
  white-space: nowrap;
  text-align: center;
  line-height: 1.3;
  letter-spacing: 0.04em;
}

/* Bird — stays at viewport center, vertically at timeline */
.bird {
  position: absolute;
  top: 80%;
  left: 50%;
  transform: translate(-50%, -100%);
  z-index: 5;
  image-rendering: pixelated;
}

.bird img {
  width: 48px;
  height: auto;
  image-rendering: pixelated;
  display: block;
}

/* Milestone polaroids — anchored above the timeline, always visible */
.milestone-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.milestone-photo {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  background: #fff;
  padding: 5px 5px 28px 5px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.1);
  border-radius: 1px;
  width: 200px;
  text-align: center;
  transform-origin: center bottom;
  opacity: 0;
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.5s ease, padding 0.25s ease;
}

.milestone-photo.active {
  padding: 5px 5px 6px 5px;
  transform: scale(var(--active-scale, 1.9)) rotate(0deg) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 4;
}

.milestone-img {
  display: block;
  width: 100%;
  height: auto;
}

.milestone-caption {
  padding: 0 4px;
  line-height: 1.2;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, padding 0.25s ease, opacity 0.25s ease;
}

.milestone-photo.active .milestone-caption {
  padding: 6px 4px 2px;
  max-height: 240px;
  opacity: 1;
}

.milestone-date {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--dusty-rose);
}

.milestone-location {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.42rem;
  color: var(--sage);
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.milestone-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.65rem;
  color: var(--dark-slate);
  margin-top: 3px;
}

.milestone-description {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 0.5rem;
  color: var(--sage);
  margin-top: 2px;
}

.photo-spinner {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--bg) 25%,
    rgba(181, 105, 108, 0.08) 50%,
    var(--bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Timeline page-level loading overlay */
.timeline-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.timeline-loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(181, 105, 108, 0.2);
  border-top-color: var(--dusty-rose);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Mobile touch controls */
.touch-controls {
  display: none;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--dusty-rose);
  background: rgba(255, 255, 255, 0.3);
  color: var(--dusty-rose);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

.touch-btn:active {
  background: var(--dusty-rose);
  color: var(--bg);
}

/* ── Scatter photos ── */
.scatter-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* When a scatter photo is active, raise the whole scatter container above
   the milestone container (z-index: 2). Without this, a scatter polaroid
   can never paint above an overlapping milestone, since each container
   forms its own stacking context. */
.scatter-container.has-active {
  z-index: 5;
}

.scatter-photo {
  position: absolute;
  transform-origin: center top;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease, padding 0.2s ease;
  background: #fff;
  padding: 4px 4px 16px 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  border-radius: 1px;
  /* Fix polaroid width so long captions wrap and extend the bottom border
     downward, instead of stretching the polaroid sideways. */
  width: 80px;
  text-align: center;
}

.scatter-photo:not(.active):hover {
  transform: scale(1.15) rotate(0deg) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  z-index: 3;
}

.scatter-photo.active,
.scatter-photo.active:hover {
  /* translateY before scale, so --active-shift is in viewport pixels (the
     translate is applied in element coords before the scale, so the visual
     translation equals the value as written). Both vars are set per-photo at
     click time so tall expansions near the viewport floor don't clip:
     the photo is shifted up first, and if it still wouldn't fit at the top
     margin, --active-scale is reduced below 3.25 to make it fit. */
  transform: translateY(var(--active-shift, 0px)) scale(var(--active-scale, 3.25)) rotate(0deg) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 4;
  padding: 4px 4px 6px 4px;
  /* Override the inline opacity set by the proximity fade in render(),
     which caps at 0.85 so off-center scatter photos stay translucent. */
  opacity: 1 !important;
}

.scatter-img {
  display: block;
  width: 100%;
  height: auto;
}

.scatter-caption {
  padding: 0 2px;
  line-height: 1.2;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  overflow-wrap: break-word;
  transition: max-height 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.scatter-photo.active .scatter-caption {
  padding: 4px 2px 2px;
  max-height: 240px;
  opacity: 1;
}

/* --caption-font-scale (set per-photo when active) counter-scales caption
   text against a bumped --active-scale, so a landscape's annotations
   render at the same visual size as a portrait's. Defaults to 1. */
.scatter-date {
  font-family: 'Montserrat', sans-serif;
  font-size: calc(0.28rem * var(--caption-font-scale, 1));
  letter-spacing: 0.05em;
  color: var(--dusty-rose);
}

.scatter-location {
  font-family: 'Montserrat', sans-serif;
  font-size: calc(0.28rem * var(--caption-font-scale, 1));
  color: var(--sage);
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.scatter-description {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: calc(0.36rem * var(--caption-font-scale, 1));
  color: var(--sage);
  margin-top: 2px;
}

/* ── Page: Cool New Tab ── */
.page-cool-new-tab {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  gap: 2rem;
  overflow: hidden;
}

.page-cool-new-tab .confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 10;
}

.page-cool-new-tab .letter {
  position: relative;
  z-index: 1;
  max-width: 620px;
  width: 100%;
  background: #FAF6EC;
  border: 1px solid rgba(181, 105, 108, 0.2);
  border-radius: 4px;
  padding: 3rem 3.25rem;
  box-shadow: 0 18px 40px -20px rgba(51, 64, 62, 0.35), 0 4px 12px -4px rgba(51, 64, 62, 0.15);
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.page-cool-new-tab .letter.revealed {
  opacity: 1;
  transform: translateY(0);
}

.page-cool-new-tab .letter h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-style: italic;
  font-size: 2.4rem;
  color: var(--dusty-rose);
  text-align: center;
  margin-bottom: 1.75rem;
  letter-spacing: 0.02em;
}

.page-cool-new-tab .letter-body {
  font-family: 'Montserrat', sans-serif;
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--dark-slate);
}

.page-cool-new-tab .letter-body p {
  margin-bottom: 1rem;
}

.page-cool-new-tab .letter-placeholder {
  font-style: italic;
  color: var(--sage);
  opacity: 0.85;
}

.page-cool-new-tab .letter-signoff {
  font-family: 'Montserrat', sans-serif;
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--dark-slate);
  margin-top: 2rem;
  /*text-align: right;*/
}

.page-cool-new-tab .signoff-name {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.5rem;
  color: var(--dusty-rose);
}

.page-cool-new-tab .replay-button {
  position: relative;
  z-index: 1;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--dark-slate);
  background: transparent;
  border: 1.5px solid var(--dark-slate);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  transition: color 0.3s, border-color 0.3s, background 0.3s;
}

.page-cool-new-tab .replay-button:hover {
  color: var(--dusty-rose);
  border-color: var(--dusty-rose);
  background: rgba(181, 105, 108, 0.06);
}

/* ── Fade transition ── */
.fade-out {
  animation: fadeOut 0.4s ease forwards;
}

.fade-in {
  animation: fadeIn 0.6s ease forwards;
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-10px); }
}

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

/* ── Mobile ── */
@media (max-width: 768px) {
  .side-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-height: auto;
    height: auto;
    flex-direction: row;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-right: none;
    border-bottom: 1px solid rgba(107, 127, 120, 0.2);
  }

  .side-nav .nav-logo {
    display: none;
  }

  .side-nav a {
    font-size: 0.95rem;
    padding: 0.45rem 0.85rem;
    border-right: none;
    border-bottom: 2px solid transparent;
    width: auto;
    white-space: nowrap;
  }

  .side-nav a.active {
    border-right: none;
    border-bottom-color: var(--dusty-rose);
    background: none;
  }

  .main-content {
    margin-left: 0;
    margin-top: 50px;
  }

  .page-home {
    flex-direction: column;
    min-height: calc(100vh - 50px);
    min-height: calc(100dvh - 50px);
    padding: 2rem 2rem;
  }

  .page-home .home-spacer {
    display: none;
  }

  .page-home .names {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.4rem;
  }

  .page-home .names h1 {
    font-size: 2.56rem;
  }

  .page-home .names .ampersand {
    font-size: 1.76rem;
    margin: 0;
  }

  .page-home .hero-image {
    width: 80%;
    max-width: 350px;
    margin: 1.5rem -2rem 2rem auto;
  }

  .page-our-story {
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 0;
    height: auto;
    max-height: none;
    padding: 0;
    overflow: hidden;
  }

  .page-our-story h2 {
    font-size: 1.5rem;
    margin: 0;
  }

  .story-header {
    flex-shrink: 0;
    padding: 0.75rem 1rem 0.5rem;
    text-align: center;
    background: var(--bg);
  }

  .timeline-viewport {
    min-height: 0;
  }

  .touch-controls {
    display: flex;
    flex-shrink: 0;
    padding: 0.25rem 1rem 0.5rem;
    justify-content: center;
    gap: 1.5rem;
  }

  .timeline-line {
    top: 85%;
  }

  .bird {
    top: 85%;
  }

  .bird img {
    transition: opacity 0.2s ease;
  }

  .bird.over-milestone img {
    opacity: 0.35;
  }

  .milestone-photo {
    width: 140px;
    padding: 4px 4px 20px 4px;
  }

  .milestone-photo.active {
    padding: 4px 4px 5px 4px;
  }

  /* Mobile uses a smaller polaroid; image fills the new width via the
     desktop "width: 100%" rule, so natural aspect is preserved. */
  .scatter-photo {
    width: 56px;
    padding: 3px 3px 10px 3px;
  }

  .story-instructions .desktop-hint {
    display: none;
  }
}

@media (min-width: 769px) {
  .story-instructions .mobile-hint {
    display: none;
  }
  .side-nav {
    justify-content: center;
    gap: 3rem;
    padding-left: 1rem;
  }
  .side-nav a {
    font-size: 1.5rem;
  }
  .timeline-line {
    top: 85%;
  }
  .bird {
    top: 85%;
  }
  .milestone-popup {
    max-width: 560px;
    bottom: calc(15% + 60px);
  }
  .milestone-popup .popup-date {
    font-size: 0.85rem;
  }
  .milestone-popup .popup-location {
    font-size: 1rem;
    margin-top: 0.55rem;
  }
  .milestone-popup .popup-title {
    font-size: 1.5rem;
  }
  .milestone-popup .popup-description {
    font-size: 1.2rem;
  }
  .milestone-popup .popup-photo.landscape {
    width: 494px;
  }
  .milestone-popup .popup-photo.portrait {
    height: min(494px, 45dvh);
    width: auto;
  }

  .page-cool-new-tab {
    min-height: calc(100vh - 50px);
    min-height: calc(100dvh - 50px);
    padding: 2rem 1.25rem;
  }

  .page-cool-new-tab .letter {
    padding: 2rem 1.75rem;
  }

  .page-cool-new-tab .letter h2 {
    font-size: 1.9rem;
    margin-bottom: 1.25rem;
  }

  .page-cool-new-tab .letter-body {
    font-size: 0.95rem;
    line-height: 1.7;
  }
}
