/* CSS Custom Properties for viewport units */
:root {
    /* Fallback viewport height for older browsers */
    --vh: 1vh;
    /* Dynamic viewport height (includes browser UI changes) */
    --dvh: 1dvh;
    /* Small viewport height (excludes browser UI) */
    --svh: 1svh;
    /* Large viewport height (includes browser UI) */
    --lvh: 1lvh;
}

/* Set viewport height custom property via JavaScript for fallback */
body, html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Seaweed Script', cursive;
    /* Prevent horizontal scroll issues */
    overflow-x: hidden;
}

body {
    overflow: hidden;
    /* iOS Safari fix for momentum scrolling */
    -webkit-overflow-scrolling: touch;
}

.page-wrapper {
    position: relative;
    /* Use dynamic viewport height with fallbacks */
    height: 100vh; /* Fallback */
    height: 100dvh; /* Dynamic viewport height for modern browsers */
    height: calc(var(--vh) * 100); /* JavaScript fallback */
    overflow-y: auto;
    /* Restore basic scroll functionality as fallback */
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    z-index: 1;
    /* Better scrolling on mobile */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

.section {
    /* Use dynamic viewport height with fallbacks */
    min-height: 100vh; /* Fallback */
    min-height: 100dvh; /* Dynamic viewport height */
    min-height: calc(var(--vh) * 100); /* JavaScript fallback */
    height: 100vh; /* Fallback */
    height: 100dvh; /* Dynamic viewport height */
    height: calc(var(--vh) * 100); /* JavaScript fallback */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 16px;
    /* Restore CSS scroll-snap as fallback */
    scroll-snap-align: center;
    scroll-snap-stop: always;
    /* Ensure sections take full viewport */
    box-sizing: border-box;
    position: relative;
    /* Better rendering on mobile */
    will-change: transform;
}

.invitation-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.home-title {
    font-size: 50px;
    line-height: 64px;
    margin-bottom: 40px;
    font-weight: 400;
    padding-top: 65px;
}

.invitation-title {
    font-size: 50px;
    line-height: 54px;
    font-weight: 400;
    margin: 0;
}

.invitation-frame {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    margin-top: -40px;
    border-width: 10px;
    border-style: solid;
    border-color: #2F2D2D #434040 #4F4C4C #434040;
    background: #f5f5f5;
    background-image: linear-gradient(#E5E4DF, #CDCDC6);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.6), 0 5px 2px rgba(0, 0, 0, 0.1), 0 10px 20px rgba(0, 0, 0, 0.8);
    position: relative;
    overflow: hidden;
    max-width: min(90vw, 960px);
    /* Use dynamic viewport height with fallbacks for more consistent behavior */
    max-height: min(75vh, 960px); /* Fallback */
    max-height: min(75dvh, 960px); /* Dynamic viewport height */
    max-height: min(calc(var(--vh) * 75), 960px); /* JavaScript fallback */
    /* Better mobile rendering */
    transform: translateZ(0);
    backface-visibility: hidden;
}

@media (min-width: 769px) {
    .invitation-title {
        margin-bottom: 32px;
    }

    .invitation-frame,
    .letter-frame-wrapper {
        margin-top: 20px;
    }
}

.invitation-frame::before {
    content: "";
    position: absolute;
    top: -175px;
    right: -20%;
    width: 400px;
    height: 400px;
    transform: rotateZ(-40deg);

}

.invitation-frame img {
    border-width: 2px;
    border-style: solid;
    border-color: #BBBAB4 #C7C7BF #E5E4DF #C7C7BF;
    box-shadow: 0 -1px 1px rgba(0, 0, 0, 0.1), 0 1px 1px 1px rgba(255, 255, 255, 0.7);
    max-width: 100%;
    height: auto;
    max-height: 100%;
}

/* Memories collage styles — start */
.memories-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    width: min(94vw, 640px);
}

.memories-title {
    font-size: 50px;
    line-height: 54px;
    font-weight: 400;
    margin: 0;
}

.memories-grid {
    display: grid;
    width: 100%;
    gap: 24px;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    justify-items: center;
}

.memory-card {
    position: relative;
    display: block;
    width: clamp(140px, 28vw, 180px);
    aspect-ratio: 3 / 4;
    --memory-frame: 12px;
    --memory-radius: 18px;
    --memory-tilt: 0deg;
    --memory-shift-x: 0px;
    --memory-shift-y: 0px;
    transform-origin: center;
    transform: translate(var(--memory-shift-x), var(--memory-shift-y)) rotate(var(--memory-tilt));
    transition: transform 0.3s ease;
}

.memories-grid:hover .memory-card {
    opacity: 0.75;
    transform: translate(var(--memory-shift-x), var(--memory-shift-y)) rotate(var(--memory-tilt)) scale(0.9);
    transition: all 0.4s ease;
}

.memory-card:focus-within,
.memory-card:hover {
    opacity: 1 !important;
    transform: translate(var(--memory-shift-x), var(--memory-shift-y)) rotate(var(--memory-tilt)) scale(1.15) !important;
    z-index: 10;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.memory-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--memory-radius);
    border: var(--memory-frame) solid #fff;
    background: transparent;
    box-shadow: 6px 6px 18px rgba(0, 0, 0, 0.2), -4px -4px 14px rgba(255, 255, 255, 0.8);
    filter: url(#wavy2);
    pointer-events: none;
    z-index: 2;
}

.memory-image {
    position: absolute;
    inset: calc(var(--memory-frame) * 0.65);
    border-radius: calc(var(--memory-radius) - var(--memory-frame) * 0.75);
    overflow: hidden;
    z-index: 1;
    left: 2px;
    top: 2px;
}

.memory-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
/* Memories collage styles — end */

.home-background-image {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    opacity: 0.6;
    z-index: -1;
    pointer-events: none;
}

.home-section {
    color: black;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
}

.home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.home-center-image {
    width: 188px;
    height: 155px;
    margin-bottom: 20px;
}

.home-date {
    font-size: 20px;
    line-height: 64px;
}

.home-quote {
    font-size: 25px;
    line-height: 30px;
}

/* Mobile-specific fixes */
@supports not (height: 100dvh) {
    /* Fallback for browsers without dynamic viewport support */
    .page-wrapper {
        height: calc(var(--vh) * 100);
    }

    .section {
        min-height: calc(var(--vh) * 100);
        height: calc(var(--vh) * 100);
    }

    .invitation-frame {
        max-height: min(calc(var(--vh) * 75), 960px);
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    .page-wrapper {
        /* Fix for iOS viewport height issues */
        min-height: -webkit-fill-available;
        height: -webkit-fill-available;
    }

    .section {
        min-height: -webkit-fill-available;
    }
}

/* Touch device optimizations */
@media (pointer: coarse) {
    .page-wrapper {
        /* Improve scroll performance on touch devices */
        scroll-behavior: auto;
        overscroll-behavior-y: none;
    }

    .section {
        /* Reduce layout shifts on touch */
        contain: layout style;
    }

    .invitation-frame {
        /* Better touch performance */
        transform: translate3d(0, 0, 0);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .invitation-title,
    .home-title {
        font-size: 50px;
        line-height: 54px;
        margin-bottom: 40px;
    }

    .home-quote {
        font-size: 22px;
        line-height: 28px;
    }

    .memories-title {
        font-size: 46px;
        line-height: 48px;
    }

    .memories-content {
        gap: 28px;
    }

    .memories-grid {
        gap: 20px;
    }

    .memory-card {
        width: clamp(130px, 34vw, 170px);
        --memory-frame: 0px;
    }
}

@media (max-width: 480px) {
    .invitation-title,
    .home-title {
        font-size: 50px;
        line-height: 42px;
        padding-bottom: 40px;
        margin: 0 0 30px 0;
    }

    .home-center-image {
        width: 150px;
        height: 124px;
    }

    .home-date {
        font-size: 18px;
        line-height: 54px;
    }

    .home-quote {
        font-size: 20px;
        line-height: 26px;
    }

    .memories-title {
        font-size: 42px;
        line-height: 44px;
    }

    .memories-content {
        gap: 24px;
    }

    .memories-grid {
        gap: 18px;
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .memory-card {
        width: clamp(120px, 42vw, 150px);
        --memory-frame: 6px;
    }

    /* Additional mobile optimizations */
    .invitation-frame {
        /* Ensure better fit on small screens */
        max-width: 95vw;
        max-height: min(70vh, 70dvh, calc(var(--vh) * 70));
        padding: 8px;
    }

    .section {
        /* Reduce padding on very small screens */
        padding: 20px 12px;
    }
}

/* Landscape mobile specific */
@media (max-width: 768px) and (orientation: landscape) {
    .invitation-frame {
        max-height: min(80vh, 80dvh, calc(var(--vh) * 80));
    }

    .section {
        padding: 20px 16px;
    }
}


/* Zoom Controls */
.zoom-controls {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: max(16px, env(safe-area-inset-left, 16px));
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.zoom-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  margin: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
}

.zoom-btn:hover {
  transform: none;
}

.zoom-btn:active {
  transform: scale(0.95);
}

.zoom-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.zoom-btn:disabled:hover {
  transform: scale(1);
}

@media (max-width: 768px) {
  .zoom-controls {
    top: max(12px, env(safe-area-inset-top, 12px));
    left: max(12px, env(safe-area-inset-left, 12px));
  }

  .zoom-btn {
    width: 36px;
    height: 36px;
  }
}

.site-nav {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
  /* Fix for iOS safe area */
  top: max(16px, env(safe-area-inset-top, 16px));
  right: max(16px, env(safe-area-inset-right, 16px));
}

.nav-trigger {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  margin: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  transition: transform 0.18s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.nav-trigger:hover,
.nav-trigger:focus-visible,
.nav-trigger:focus {
  transform: scale(1.08);
  outline: none;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}

.nav-trigger-bar {
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: #fff;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.site-nav.is-open .nav-trigger-bar:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.site-nav.is-open .nav-trigger-bar:nth-child(2) {
  opacity: 0;
}

.site-nav.is-open .nav-trigger-bar:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

.nav-sheet {
  pointer-events: auto;
  margin: 0;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 16px;
  padding: 12px 20px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  display: flex;
  animation: nav-pop 0.18s ease-out;
}

.nav-sheet[hidden] {
  display: none;
}

@keyframes nav-pop {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.nav-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-menu a {
  font-family: 'Seaweed Script', cursive;
  font-size: 24px;
  line-height: 1;
  text-decoration: none;
  color: #fff;
  transition: opacity 0.2s ease;
}

.nav-menu a:hover,
.nav-menu a:focus {
  opacity: 0.7;
}

button {
  font-family: 'Seaweed Script', cursive;
  font-size: 20px;
  font-weight: bold;
  color: #000000;
  padding: 10px 20px;
  border-radius: 10px;
  border: 2px solid #fafafa;
  background: #ebe3e3;
  box-shadow: 3px 3px #fafafa;
  cursor: pointer;
  margin: 5px 0;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  box-shadow: none;
  transform: translate(3px, 3px);
}

/* Family section spacing fix */
.memories-section#family {
  margin-bottom: 0;
  padding-bottom: 40px;
}

/* Jab We Met section styles */

.jab-we-met-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(94vw, 800px);
  margin: 0 auto;
  padding-top: 0;
}

.jab-we-met-title {
  font-size: 50px;
  line-height: 54px;
  font-weight: 400;
  margin: 0 0 40px 0;
}

.poem-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.poem-text {
  font-size: 22px;
  line-height: 1.8;
  text-align: left;
  max-width: 600px;
  color: #1a1a1a;
  font-family: 'Kalam', sans-serif;
  font-weight: 600;
  letter-spacing: 0.5px;
}

@media (max-width: 768px) {
  .jab-we-met-title {
    font-size: 46px;
    line-height: 48px;
  }

  .poem-text {
    font-size: 20px;
    line-height: 1.5;
  }
}

@media (max-width: 480px) {
  .jab-we-met-section {
    padding: 40px 16px;
  }

  .jab-we-met-title {
    font-size: 42px;
    line-height: 44px;
    margin-bottom: 30px;
  }

  .poem-text {
    font-size: 18px;
    line-height: 1.4;
  }
}

/* Family toggle switch styles */
.family-toggle-container {
  display: flex;
  justify-content: center;
  margin-top: 5px;
}

.toggle-switch {
  position: relative;
  display: flex;
  align-items: center;
  background: #FBF6F6;
  border-radius: 10px;
  box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  padding: 8px 5px;
  cursor: pointer;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.toggle-track {
  position: absolute;
  width: calc(50% - 2px);
  height: calc(100% - 4px);
  top: 2px;
  left: 2px;
  background: #EBE3E3;
  border-radius: 10px;
  transition: transform 0.3s ease;
  z-index: 1;
}

.toggle-switch.active .toggle-track {
  transform: translateX(100%);
}

.toggle-label {
  font-family: 'Seaweed Script', cursive;
  font-weight: bold;
  font-size: 20px;
  color: #000000;
  cursor: pointer;
  user-select: none;
  position: relative;
  z-index: 2;
  padding: 6px 10px;
  min-width: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
  .site-nav {
    top: 12px;
    right: 12px;
    gap: 6px;
  }

  .nav-trigger {
    width: 40px;
    height: 40px;
  }

  .nav-sheet {
    padding: 10px 16px;
  }

  .nav-menu {
    gap: 10px;
  }
}

/* Scroll arrow styles */
.scroll-arrow {
  position: absolute;
  bottom: 0px;
  left: 50%;
  transform: translateX(-50%);
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.3s ease, transform 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  animation: bounce 2s infinite;
  color: #000;
}

.scroll-arrow:hover {
  opacity: 0.8;
  transform: translateX(-50%) scale(1.1);
}

.scroll-arrow:active {
  transform: translateX(-50%) scale(0.95);
}

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

@media (max-width: 480px) {
  .scroll-arrow {
    bottom: 30px;
  }

  .scroll-arrow svg {
    width: 50px;
    height: 50px;
  }
}

/* Letter section styles */
.letter-frame-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  margin-top: -40px;
  border-width: 10px;
  border-style: solid;
  border-color: #2F2D2D #434040 #4F4C4C #434040;
  background: #f5f5f5;
  background-image: linear-gradient(#E5E4DF, #CDCDC6);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.6), 0 5px 2px rgba(0, 0, 0, 0.1), 0 10px 20px rgba(0, 0, 0, 0.8);
  position: relative;
  overflow: hidden;
  max-width: min(90vw, 960px);
  height: min(70vh, 720px);
  height: min(65dvh, 720px);
  height: calc(var(--vh, 1vh) * 70);
  transform: translateZ(0);
  backface-visibility: hidden;
}

.letter-frame-wrapper img {
  border-width: 2px;
  border-style: solid;
  border-color: #BBBAB4 #C7C7BF #E5E4DF #C7C7BF;
  box-shadow: 0 -1px 1px rgba(0, 0, 0, 0.1), 0 1px 1px 1px rgba(255, 255, 255, 0.7);
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.letter-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #000;
  font-family: 'Satisfy';
  width: 70%;
  line-height: 1.5;
  z-index: 10;
}

.letter-text p {
  margin: 0 0 14px 0;
  font-size: 24px;
}

.letter-text .names {
  font-size: 26px;
  margin: 18px 0;
  line-height: 1.5;
}

.letter-text .names strong {
  font-size: 30px;
  font-weight: 700;
}

.letter-text .to-text {
  font-size: 24px;
  margin: 5px 0;
  font-style: italic;
}

.letter-text .closing-text {
  font-size: 22px;
  margin: 18px 0 14px 0;
  line-height: 1.5;
}

.letter-text .info-text {
  font-size: 20px;
  margin: 14px 0 0 0;
  line-height: 1.4;
  font-style: italic;
}

@media (min-width: 1024px) {
  .letter-frame-wrapper {
    height: min(85vh, 860px);
  }

  .letter-frame-wrapper img {
    object-position: center;
  }
}

@media (max-width: 768px) {
  .letter-text {
    width: 82%;
  }

  .letter-text p {
    font-size: 21px;
  }

  .letter-text .names {
    font-size: 23px;
  }

  .letter-text .names strong {
    font-size: 26px;
  }

  .letter-text .to-text {
    font-size: 21px;
  }

  .letter-text .closing-text {
    font-size: 20px;
  }

  .letter-text .info-text {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  .letter-frame {
    max-width: 95vw;
    height: min(90vh, 90dvh, calc(var(--vh) * 90));
  }

  .letter-text {
    width: 85%;
  }

  .letter-text p {
    font-size: 18px;
    margin: 0 0 11px 0;
  }

  .letter-text .names {
    font-size: 20px;
    margin: 13px 0;
  }

  .letter-text .names strong {
    font-size: 23px;
  }

  .letter-text .to-text {
    font-size: 18px;
    margin: 11px 0;
  }

  .letter-text .closing-text {
    font-size: 17px;
    margin: 13px 0 11px 0;
  }

  .letter-text .info-text {
    font-size: 15px;
    margin: 11px 0 0 0;
  }
}

/* Viewport height based media queries for small screens */
@media (max-height: 700px) {
  .letter-text {
    width: 88%;
    line-height: 1.3;
  }

  .letter-text p {
    font-size: 16px;
    margin: 0 0 8px 0;
  }

  .letter-text .names {
    font-size: 18px;
    margin: 10px 0;
    line-height: 1.3;
  }

  .letter-text .names strong {
    font-size: 20px;
  }

  .letter-text .to-text {
    font-size: 16px;
    margin: 8px 0;
  }

  .letter-text .closing-text {
    font-size: 15px;
    margin: 10px 0 8px 0;
    line-height: 1.3;
  }

  .letter-text .info-text {
    font-size: 13px;
    margin: 8px 0 0 0;
    line-height: 1.3;
  }
}

@media (max-height: 600px) {
  .letter-text p {
    font-size: 14px;
    margin: 0 0 6px 0;
  }

  .letter-text .names {
    font-size: 16px;
    margin: 8px 0;
  }

  .letter-text .names strong {
    font-size: 18px;
  }

  .letter-text .to-text {
    font-size: 14px;
    margin: 6px 0;
  }

  .letter-text .closing-text {
    font-size: 13px;
    margin: 8px 0 6px 0;
  }

  .letter-text .info-text {
    font-size: 11px;
    margin: 6px 0 0 0;
  }
}
