:root {
    --bg-color: #0f0c1b;
    --text-color: #fdf0f5;
    --accent-color: #ff4b72;
    --font-primary: 'Outfit', sans-serif;
    --font-script: 'Dancing Script', cursive;
}

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

/* Prevent image and video downloading and saving */
img, video, .photo, .letter-photo, .page-img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    -webkit-touch-callout: none; /* Disables iOS save image popup */
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-primary);
    overflow: hidden; /* Prevent scrolling, handle transitions in JS */
    touch-action: none; /* For swipe handling */
    width: 100vw;
    height: 100vh;
}

#main-content {
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
}

#bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    opacity: 0.4;
    transition: opacity 0.5s ease-in-out;
}

#bg-layer video, #bg-layer img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Password Screen Styling */
#password-screen {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: linear-gradient(135deg, rgba(15, 12, 27, 0.95), rgba(30, 20, 50, 0.95));
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 1s ease;
}

.password-container {
    background: rgba(255, 255, 255, 0.05);
    padding: 3rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    max-width: 400px;
    width: 90%;
}

.password-container h2 {
    font-family: var(--font-script);
    font-size: 3rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
}

.password-container p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    opacity: 0.8;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#password-input {
    padding: 1rem;
    border: 1px solid rgba(255, 75, 114, 0.3);
    border-radius: 8px;
    background: rgba(0,0,0,0.2);
    color: white;
    font-family: var(--font-primary);
    font-size: 1.2rem;
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
}

#password-input:focus {
    border-color: var(--accent-color);
}

#password-submit {
    padding: 1rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, background 0.3s;
}

#password-submit:hover {
    transform: translateY(-2px);
    background: #ff335e;
}

.error-msg {
    color: #ff4b4b !important;
    font-size: 0.9rem !important;
    margin-top: 1rem !important;
    margin-bottom: 0 !important;
    opacity: 0 !important;
    transition: opacity 0.3s;
}

.error-msg.visible {
    opacity: 1 !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

/* Base Scene Styling */
.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1s ease, transform 1s cubic-bezier(0.25, 1, 0.5, 1);
    padding: 2rem;
    text-align: center;
}

.scene.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.scene.exit-prev {
    transform: translateY(-50px) scale(0.95);
}

.scene.enter-next {
    transform: translateY(50px) scale(1.05);
}

/* Typography */
h1, h2 {
    font-family: var(--font-script);
    font-weight: 600;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(255, 75, 114, 0.4);
}

p {
    font-size: 1.2rem;
    line-height: 1.6;
    max-width: 600px;
}

.heart {
    color: var(--accent-color);
    display: inline-block;
    animation: pulse 2s infinite;
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(2deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

/* Navigation Overlay */
.nav-overlay {
    position: absolute;
    bottom: 4rem;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 10%;
    pointer-events: none;
    z-index: 100;
    opacity: 0.7;
    transition: opacity 0.5s;
    box-sizing: border-box;
}
.nav-arrow {
    font-family: var(--font-primary);
    font-size: 0.9rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    pointer-events: auto; /* enable click on arrows */
    cursor: pointer;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.2);
    transition: background 0.3s, transform 0.3s;
}
.nav-arrow:hover {
    background: rgba(255, 75, 114, 0.7);
    transform: scale(1.05);
}
.nav-next {
    animation: pulse 2s infinite;
}

/* Specific Scenes */
.scene-intro h1 {
    font-size: 4rem;
}

.scene-message p {
    font-size: 1.5rem;
    font-weight: 300;
}

/* Memories Scene */
.photo-stack {
    position: relative;
    width: 250px;
    height: 300px;
}
.memory-photo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 8px solid white;
    opacity: 0;
    transform: scale(0.8) rotate(0deg);
    transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.memory-photo.visible {
    opacity: 1;
}

/* Photo Letters Scene */
.letters-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.letter-photo {
    position: absolute;
    background-color: #fff;
    background-size: cover;
    background-position: center;
    border-radius: 2px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: all 1.5s cubic-bezier(0.25, 1, 0.5, 1);
    opacity: 0;
    /* initially random positions */
}
/* Increase tap area for tiny mobile photos */
.letter-photo::after {
    content: '';
    position: absolute;
    top: -10px; left: -10px; right: -10px; bottom: -10px;
}
.letter-photo.scattered {
    opacity: 1;
}

/* Collage Scene */
.collage-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 500px;
}
.collage-item {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.6s ease;
}
.scene.active .collage-item {
    opacity: 1;
    transform: translateY(0);
}

/* Envelope */
.envelope-container {
    perspective: 1000px;
    cursor: pointer;
    position: relative;
    width: 300px;
    height: 200px;
    margin-bottom: 280px;
}
.envelope {
    width: 100%;
    height: 100%;
    background: #d4a373;
    position: relative;
    border-radius: 5px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    transform-style: preserve-3d;
    transition: transform 1s;
}
.envelope.open {
    transform: rotateX(180deg);
}
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: #faedcd;
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    transform-origin: top;
    transition: transform 0.6s 0.2s;
    z-index: 3;
}
.envelope.open .envelope-flap {
    transform: rotateX(180deg);
    z-index: 1;
}
.letter-paper {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    height: 180px;
    background: #fefae0;
    color: #333;
    padding: 20px;
    box-sizing: border-box;
    border-radius: 5px;
    transition: transform 0.8s 0.6s, height 0.8s 0.6s;
    z-index: 2;
    overflow-y: auto;
    /* Custom scrollbar for letter */
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) transparent;
}
.letter-paper::-webkit-scrollbar {
    width: 6px;
}
.letter-paper::-webkit-scrollbar-thumb {
    background-color: var(--accent-color);
    border-radius: 3px;
}
.envelope.open .letter-paper {
    height: 380px;
    transform: translateY(-80px) rotateX(180deg);
    z-index: 4;
}
.letter-paper h2 {
    font-family: var(--font-script);
    color: var(--accent-color);
    font-size: 2rem;
    margin-bottom: 0.5rem;
    text-shadow: none;
}
.letter-paper p {
    font-size: 0.9rem;
    font-family: var(--font-primary);
    line-height: 1.4;
}
.envelope-front {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ccd5ae;
    clip-path: polygon(0 100%, 50% 40%, 100% 100%, 100% 100%, 0 100%);
    z-index: 3;
}
.envelope-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #e9edc9;
    z-index: 1;
}

/* Lightbox Modal */
.lightbox {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.lightbox.active {
    opacity: 1;
    pointer-events: auto;
}
#lightbox-img {
    max-width: 95%;
    max-height: 95%;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    object-fit: contain;
}
.lightbox.active #lightbox-img {
    transform: scale(1);
}
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 3rem;
    cursor: pointer;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.memory-photo, .collage-item, .letter-photo {
    cursor: pointer;
}

/* Particles */
.particle {
    position: absolute;
    pointer-events: none;
    background: radial-gradient(circle, var(--accent-color) 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0.6;
}
/* Notebook */
.scene-notebook {
    align-items: center;
    justify-content: center;
}
.notebook-container {
    perspective: 1500px;
    width: 90vw;
    max-width: 450px;
    height: 70vh;
    max-height: 600px;
    margin: 0 auto;
}
.notebook {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(2deg) rotateY(-2deg);
    transition: transform 0.5s;
}
.notebook-page {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: left center;
    transition: transform 1s cubic-bezier(0.645, 0.045, 0.355, 1);
    transform-style: preserve-3d;
    box-shadow: 2px 0 15px rgba(0,0,0,0.3);
    border-radius: 5px 15px 15px 5px;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
}
/* ONLY enable clicks when the scene is active to prevent invisible shield bug! */
.scene.active .notebook-page {
    pointer-events: auto;
}
.notebook-page.flipped {
    transform: rotateY(-160deg); /* not fully 180 so it stacks visually */
}

/* Cover */
.notebook-page.cover {
    background: linear-gradient(135deg, #ff4b72, #ff758c);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    border-left: 10px solid #d43b5d;
}
.notebook-page.cover h1 {
    font-size: 3.5rem;
    text-shadow: 0 4px 10px rgba(0,0,0,0.3);
    text-align: center;
    padding: 20px;
    font-family: var(--font-secondary);
}
.notebook-page.back-cover {
    background: #d43b5d;
}

/* Inner pages */
.notebook-page.inner-page {
    display: flex;
    flex-direction: column;
    border-left: 2px solid #ccc;
    background: #fdfdfd;
}
.page-img {
    height: 40%;
    width: 100%;
    background-size: cover;
    background-position: center;
    border-bottom: 3px solid var(--accent-color);
}
.page-text {
    height: 60%;
    padding: 2rem;
    font-size: 0.95rem;
    color: #333;
    overflow-y: auto;
    font-family: var(--font-primary);
    line-height: 1.6;
}
.page-hint {
    position: absolute;
    bottom: 10px;
    right: 15px;
    font-size: 0.8rem;
    color: #999;
    font-style: italic;
}
.next-button {
    margin-top: 1.5rem;
    padding: 10px 20px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 20px;
    font-family: var(--font-primary);
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 75, 114, 0.4);
    align-self: center;
}

@media (max-width: 600px) {
    .scene-message p { font-size: 1.2rem; }
    .collage-grid { max-width: 90vw; }
}

/* Background Layer */
#bg-layer {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    background: var(--bg-color);
}
#bg-layer video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.5; /* dim the background video slightly for text readability */
}

/* Lightbox Video */
#lightbox-video {
    max-width: 95%;
    max-height: 95%;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    object-fit: contain;
}
.lightbox.active #lightbox-video {
    transform: scale(1);
}

/* Media Grids (Moments & Videos) */
.scene-media-grid {
    align-items: center;
    padding: 10vh 5vw;
}
.media-grid-container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.media-grid-container h2 {
    margin-bottom: 2rem;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}
.media-grid {
    display: grid;
    /* Use auto-fit for responsive tiles instead of strict 2 columns */
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    grid-auto-rows: 1fr; /* Keep tiles perfectly square based on width */
    align-content: start; /* Prevents grid from squishing all rows into the max-height */
    gap: 15px;
    width: 100%;
    max-height: 65vh;
    overflow-y: auto;
    padding: 10px;
}
.media-grid::-webkit-scrollbar { display: none; }
.media-grid { -ms-overflow-style: none; scrollbar-width: none; }

.media-item {
    width: 100%;
    aspect-ratio: 1; /* Square thumbnails */
    border-radius: 10px;
    background-size: cover;
    background-position: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    overflow: hidden;
    position: relative;
    background-color: rgba(255,255,255,0.1);
}
.media-item:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 25px rgba(255, 75, 114, 0.5);
}
.media-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none; /* Let the div catch the click */
}
.video-icon {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 3rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
    opacity: 0.8;
}

/* Question Scene */
.question-container {
    text-align: center;
    padding: 20px;
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.question-container h2 {
    font-size: 1rem;
    margin-bottom: 3rem;
    padding: 0 8px;
    line-height: 1.2;
}
.buttons-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    position: relative;
}
.btn-yes, .btn-no {
    padding: 15px 40px;
    font-size: 1.5rem;
    font-family: var(--font-primary);
    font-weight: 600;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    transition: transform 0.2s, top 0.2s, left 0.2s;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.btn-yes {
    background: var(--accent-color);
    color: white;
}
.btn-yes:hover {
    transform: scale(1.1);
}
.btn-no {
    background: #555;
    color: white;
    z-index: 1000;
    position: relative; /* Will be changed to fixed dynamically */
}
