﻿/* ==============================
   RESET & BASE
============================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Georgia', serif;
    touch-action: pan-y;
}

/* ==============================
   SCENE SYSTEM
============================== */
#storyWrapper {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
}

.scene {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.scene.hidden {
    opacity: 0;
    pointer-events: none;
}

.scene.entering {
    animation: sceneEnter 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes sceneEnter {
    from { opacity: 0; transform: scale(0.97); }
    to   { opacity: 1; transform: scale(1); }
}

.scene-content {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 420px;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

/* ==============================
   BACKGROUNDS
============================== */
.scene-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.bg-dawn {
    background: linear-gradient(160deg, #ffecd2 0%, #fcb69f 30%, #ff9a9e 60%, #fad0c4 100%);
}

.bg-morning {
    background: linear-gradient(170deg, #a8edea 0%, #fed6e3 40%, #c9f0f5 70%, #d4f7d8 100%);
}

.bg-garden {
    background: linear-gradient(160deg, #d4f7d8 0%, #a8e6a3 30%, #f0fad8 60%, #e8f5e9 100%);
}

.bg-twilight {
    background: linear-gradient(160deg, #1a0533 0%, #3d1070 30%, #6a1f8a 60%, #9b2fb5 100%);
}

.bg-warm {
    background: linear-gradient(160deg, #fff8e7 0%, #ffe0b2 30%, #ffd7e4 60%, #fff0f5 100%);
}

/* ==============================
   NAV DOTS & NEXT BUTTON
============================== */
.nav-dots {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 1000;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
    border: 1px solid rgba(255,255,255,0.6);
    cursor: pointer;
    transition: all 0.3s ease;
}

.dot.active {
    background: white;
    transform: scale(1.3);
}

.next-btn {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(255,255,255,0.72);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(180,120,160,0.35);
    color: #5a2d4a;
    font-family: 'Georgia', serif;
    font-size: 1rem;
    padding: 12px 36px;
    border-radius: 50px;
    cursor: pointer;
    letter-spacing: 0.05em;
    text-shadow: none;
    transition: all 0.25s ease;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

/* On dark scene (twilight) use white text */
#scene4 .next-btn-proxy,
.scene.bg-twilight ~ * .next-btn { color: white; }

.next-btn:hover, .next-btn:active {
    background: rgba(255,255,255,0.9);
    transform: translateX(-50%) translateY(-1px);
}

/* Button locked state (scene 1 before letter is read) */
.next-btn:disabled, .next-btn.locked {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* ==============================
   SCENE TITLE
============================== */
.scene-title-wrap {
    text-align: center;
    margin-bottom: 8px;
}

.scene-label {
    font-size: 0.8rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(80,40,60,0.6);
    font-family: sans-serif;
    margin-bottom: 4px;
}

.scene-headline {
    font-size: clamp(1.3rem, 5vw, 2rem);
    color: #5a2d4a;
    font-style: italic;
    text-shadow: 0 2px 8px rgba(200,100,150,0.2);
}

/* Scene sub-text (under flower garden and heart) */
.scene-subtext {
    font-family: 'Georgia', serif;
    font-size: 0.9rem;
    font-style: italic;
    color: #4a6a40;
    text-align: center;
    padding: 0 12px;
    opacity: 0;
    animation: fadeUp 0.8s ease-out 2.2s forwards;
}

.scene-subtext--light {
    color: rgba(255,220,240,0.9);
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ==============================
   SCENE 1: ENVELOPE & LETTER
============================== */
.envelope-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
    max-width: 320px;
}

.envelope {
    width: 280px;
    height: 180px;
    position: relative;
    cursor: pointer;
    transition: transform 0.3s ease;
    filter: drop-shadow(0 8px 24px rgba(200,100,120,0.25));
}

.envelope:hover { transform: scale(1.03); }

.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 140px solid transparent;
    border-right: 140px solid transparent;
    border-top: 95px solid #f48a98;
    z-index: 3;
    transform-origin: top center;
    transition: transform 0.5s cubic-bezier(0.4,0,0.2,1);
}

.envelope.open .envelope-flap {
    transform: rotateX(180deg);
}

.envelope-body {
    position: absolute;
    inset: 0;
    background: #ffc4ce;
    border-radius: 4px 4px 12px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.envelope-body::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    border-bottom: 95px solid #f07080;
    border-right: 140px solid transparent;
}

.envelope-body::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    border-bottom: 95px solid #e86070;
    border-left: 140px solid transparent;
}

.envelope-heart {
    width: 50px;
    height: 50px;
    position: relative;
    z-index: 2;
    animation: heartBeat 1.5s ease-in-out infinite;
}

.env-heart-path {
    fill: #e0184e;
    stroke: none;
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    30%       { transform: scale(1.12); }
    60%       { transform: scale(0.97); }
}

/* Letter */
.letter {
    width: 260px;
    background: #fffdf8;
    border-radius: 4px;
    padding: 20px 20px 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    border: 1px solid #f5e0c8;
    transform: translateY(-20px) scale(0.95);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    position: relative;
}

.letter.revealed {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.letter::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, #ff9ec4, #ffb347, #ff9ec4);
    border-radius: 4px 4px 0 0;
}

.letter-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #b88a8a;
    font-family: sans-serif;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #f5d0c8;
}

.letter-text {
    font-size: 0.92rem;
    color: #5a3030;
    line-height: 1.7;
    min-height: 60px;
    font-style: italic;
}

.letter-signature {
    margin-top: 14px;
    text-align: right;
    font-size: 0.75rem;
    color: #b88a8a;
    font-family: sans-serif;
}

.sig-name {
    font-family: 'Georgia', serif;
    font-size: 1.1rem;
    color: #c0184e;
    font-style: italic;
    margin-top: 2px;
}

/* Blinking cursor */
.cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #c0184e;
    animation: blink 0.7s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
}

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

.tap-hint {
    position: fixed;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: rgba(100,40,60,0.7);
    font-family: sans-serif;
    letter-spacing: 0.05em;
    animation: hintPulse 2s ease-in-out infinite;
    white-space: nowrap;
    z-index: 100;
}

@keyframes hintPulse {
    0%, 100% { opacity: 0.6; transform: translateX(-50%) translateY(0); }
    50%       { opacity: 1;   transform: translateX(-50%) translateY(-3px); }
}

/* ==============================
   SCENE 2: MEMORY NIGHT
============================== */
.bg-nightmemory {
    background: linear-gradient(160deg, #06001a 0%, #120235 30%, #1e0550 60%, #2a0a6e 100%);
}

.mem-label {
    color: rgba(190, 160, 255, 0.75) !important;
}

.mem-headline {
    color: rgba(220, 195, 255, 0.95) !important;
    text-shadow: 0 0 24px rgba(160, 80, 255, 0.4), 0 2px 8px rgba(0,0,0,0.5) !important;
}

.memory-stage {
    position: relative;
    width: 100%;
    height: 155px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.memory-moon {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: moonRise 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s forwards;
    filter: drop-shadow(0 0 18px rgba(255, 230, 100, 0.35));
}

@keyframes moonRise {
    from { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.mem-star {
    position: absolute;
    border-radius: 50%;
    background: white;
    opacity: 0;
}

.s1  { width:3px; height:3px; left:8%;   top:12%; animation: starAppear 0.4s ease-out 0.9s forwards, starGlow 3s ease-in-out 1.3s infinite; }
.s2  { width:5px; height:5px; left:82%;  top:8%;  animation: starAppear 0.4s ease-out 1.1s forwards, starGlow 3s ease-in-out 1.5s infinite; }
.s3  { width:2px; height:2px; left:92%;  top:35%; animation: starAppear 0.4s ease-out 1.3s forwards, starGlow 3s ease-in-out 1.7s infinite; }
.s4  { width:4px; height:4px; left:4%;   top:55%; animation: starAppear 0.4s ease-out 0.7s forwards, starGlow 3s ease-in-out 1.1s infinite; }
.s5  { width:3px; height:3px; left:18%;  top:78%; animation: starAppear 0.4s ease-out 1.5s forwards, starGlow 3s ease-in-out 1.9s infinite; }
.s6  { width:5px; height:5px; left:78%;  top:72%; animation: starAppear 0.4s ease-out 0.8s forwards, starGlow 3s ease-in-out 1.2s infinite; }
.s7  { width:2px; height:2px; left:42%;  top:5%;  animation: starAppear 0.4s ease-out 1.2s forwards, starGlow 3s ease-in-out 1.6s infinite; }
.s8  { width:3px; height:3px; left:95%;  top:58%; animation: starAppear 0.4s ease-out 1.0s forwards, starGlow 3s ease-in-out 1.4s infinite; }
.s9  { width:4px; height:4px; left:60%;  top:90%; animation: starAppear 0.4s ease-out 1.6s forwards, starGlow 3s ease-in-out 2.0s infinite; }
.s10 { width:2px; height:2px; left:25%;  top:20%; animation: starAppear 0.4s ease-out 0.6s forwards, starGlow 3s ease-in-out 1.0s infinite; }
.s11 { width:3px; height:3px; left:70%;  top:22%; animation: starAppear 0.4s ease-out 1.4s forwards, starGlow 3s ease-in-out 1.8s infinite; }
.s12 { width:2px; height:2px; left:55%;  top:80%; animation: starAppear 0.4s ease-out 1.7s forwards, starGlow 3s ease-in-out 2.1s infinite; }

@keyframes starAppear {
    from { opacity: 0; transform: scale(0); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes starGlow {
    0%, 100% { opacity: 0.4; box-shadow: 0 0 2px white; }
    50%       { opacity: 1;   box-shadow: 0 0 6px 2px rgba(255,255,255,0.6); }
}

.memory-phrases {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    padding: 0 4px;
}

.mem-phrase {
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    animation: memReveal 0.9s ease-out forwards;
}

.p1 { animation-delay: 1.6s; }
.p2 { animation-delay: 2.6s; }
.p3 { animation-delay: 3.6s; }

@keyframes memReveal {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}

.mem-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

.mem-text {
    font-family: 'Georgia', serif;
    font-style: italic;
    font-size: 0.88rem;
    color: rgba(225, 205, 255, 0.92);
    line-height: 1.55;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
/* ==============================
   SCENE 3: BOUQUET ASSEMBLY
============================== */
.bouquet-stage {
    width: 100%;
    display: flex;
    justify-content: center;
    /* overflow visible so flowers can fly in from off-screen */
}

.bouquet-wrap {
    position: relative;
    width: 280px;
    height: 200px;
}

/* Each flower: starts off-screen, transitions to bouquet position */
.fly-flower {
    position: absolute;
    bottom: 28px;
    left: 50%;
    width: 44px;
    height: 120px;
    transform-origin: bottom center;
    opacity: 0;
    /* Starting state: translated off-screen + pre-rotated + scaled down */
    transform: translateX(calc(-50% + var(--sx))) translateY(var(--sy)) rotate(var(--sr)) scale(0.3);
    transition: transform 0.85s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.6s ease;
    will-change: transform, opacity;
}

/* Final bouquet position — rotate around stem base to fan outward */
.fly-flower.landed {
    transform: translateX(-50%) rotate(var(--angle));
    opacity: 1;
}

/* Z-ordering: center flowers on top */
.ff1 { z-index: 1; }
.ff2 { z-index: 3; }
.ff3 { z-index: 5; }
.ff4 { z-index: 7; }
.ff5 { z-index: 6; }
.ff6 { z-index: 4; }
.ff7 { z-index: 2; }

/* Ribbon at the bottom center of the bouquet */
.bouquet-ribbon {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    opacity: 0;
    transition: opacity 0.7s ease;
}

.bouquet-ribbon.visible {
    opacity: 1;
}

/* ==============================
   SCENE 4: HEART
============================== */
.heart-scene {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.floating-hearts-bg {
    position: absolute;
    inset: -100px;
    pointer-events: none;
}

.fh {
    position: absolute;
    width: 0;
    height: 0;
    animation: floatUp 4s ease-in infinite;
}

.fh::before, .fh::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50% 50% 0 50%;
    background: rgba(255,100,150,0.3);
}
.fh::before { transform: rotate(-45deg); }
.fh::after  { left: 15px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }

.fh1  { bottom: 10%; left: 10%;  animation-delay: 0s;   }
.fh2  { bottom: 5%;  left: 30%;  animation-delay: 0.7s; }
.fh3  { bottom: 15%; left: 55%;  animation-delay: 1.4s; }
.fh4  { bottom: 8%;  right: 10%; animation-delay: 0.3s; }
.fh5  { bottom: 20%; left: 20%;  animation-delay: 2s;   }
.fh6  { bottom: 12%; right: 25%; animation-delay: 1s;   }

@keyframes floatUp {
    0%   { transform: translateY(0)    scale(0.8); opacity: 0.8; }
    80%  { opacity: 0.4; }
    100% { transform: translateY(-200px) scale(1.2); opacity: 0; }
}

.big-heart-container {
    position: relative;
    width: 220px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.big-heart-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    filter: drop-shadow(0 8px 24px rgba(200,0,80,0.4));
}

/* Outline drawn via stroke-dashoffset */
.heart-draw-path {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    animation: drawHeart 2.2s ease-in-out forwards;
}

@keyframes drawHeart {
    to { stroke-dashoffset: 0; }
}

/* Fill fades in after outline completes */
.heart-fill-path {
    opacity: 0;
    animation: heartFill 0.9s ease-out 2.0s forwards;
}

@keyframes heartFill {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Shine appears after fill */
.heart-shine-path {
    opacity: 0;
    animation: shineReveal 0.5s ease-out 2.8s forwards;
}

@keyframes shineReveal {
    to { opacity: 1; }
}

/* After drawing is complete: gentle float (added by JS) */
.big-heart-svg.formed {
    animation: heartFloat 3s ease-in-out infinite;
}

@keyframes heartFloat {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-7px); }
}

.heart-message {
    position: relative;
    z-index: 2;
    text-align: center;
    color: white;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.heart-msg-line {
    opacity: 0;
    transform: translateY(8px);
    animation: msgReveal 0.6s ease-out forwards;
}

.l1 { font-family: sans-serif; font-size: 0.85rem; letter-spacing: 0.1em; animation-delay: 2.4s; }
.l2 { font-family: 'Georgia', serif; font-size: 2rem; font-style: italic; animation-delay: 2.8s; font-weight: bold; }
.l3 { font-family: sans-serif; font-size: 0.85rem; letter-spacing: 0.08em; animation-delay: 3.2s; }

@keyframes msgReveal {
    to { opacity: 1; transform: translateY(0); }
}

.stars-wrap {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.star-dot {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: calc(6px * var(--s));
    height: calc(6px * var(--s));
    background: rgba(255,255,255,0.8);
    border-radius: 50%;
    animation: starTwinkle 2s ease-in-out var(--d) infinite alternate;
}

@keyframes starTwinkle {
    from { opacity: 0.2; transform: scale(0.8); }
    to   { opacity: 1;   transform: scale(1.2); }
}

/* ==============================
   SCENE 5: FINAL CARD
============================== */
#scene5 .scene-content {
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 120px);
    padding-top: 16px;
    padding-bottom: 24px;
    gap: 12px;
}

.final-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.card-paper {
    background: #fffdf8;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
    border: 1px solid #f0dcc8;
    width: 100%;
    max-width: 240px;
    animation: cardReveal 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes cardReveal {
    from { opacity: 0; transform: scale(0.85) rotate(-2deg); }
    to   { opacity: 1; transform: scale(1) rotate(0deg); }
}

.drawing-svg {
    width: 100%;
    height: auto;
    display: block;
}

.draw-sun {
    animation: sunSpin 8s linear infinite;
    transform-origin: 245px 45px;
}

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

.final-text {
    text-align: center;
    padding: 0 8px;
    animation: fadeUp 0.8s ease-out 0.8s both;
}

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

.final-name {
    font-family: 'Georgia', serif;
    font-size: 1.4rem;
    color: #c0184e;
    font-style: italic;
    margin-bottom: 8px;
}

.final-message {
    font-size: 0.88rem;
    color: #5a3030;
    line-height: 1.7;
    font-style: italic;
    margin-bottom: 14px;
}

/* Poetic paragraphs for scene 5 */
.final-para {
    font-size: 0.8rem;
    color: #5a3030;
    line-height: 1.72;
    font-style: italic;
    text-align: center;
    margin-bottom: 2px;
    opacity: 0;
    animation: fadeUp 0.8s ease-out forwards;
}

.fp1 { animation-delay: 0.9s; }
.fp2 { animation-delay: 1.4s; }
.fp3 { animation-delay: 1.9s; }
.fp4 { animation-delay: 2.4s; }

.final-closing {
    font-family: 'Georgia', serif;
    font-size: 1.0rem;
    color: #c0184e;
    font-weight: bold;
    text-align: center;
    line-height: 1.5;
    margin: 6px 0 8px;
    opacity: 0;
    animation: fadeUp 0.8s ease-out 2.9s forwards;
}

.final-wish {
    font-family: 'Georgia', serif;
    font-size: 1.1rem;
    color: #8e44ad;
    margin-bottom: 6px;
}

.final-sig {
    font-size: 0.78rem;
    color: #aaa;
    font-family: sans-serif;
    letter-spacing: 0.08em;
}

/* ==============================
   RESPONSIVE (very small phones)
============================== */
@media (max-height: 620px) {
    .scene-content { gap: 8px; }
    .walk-stage     { height: 160px; }
    .flower-garden  { height: 190px; }
    .final-message  { display: none; }
    .card-paper     { max-width: 280px; }
}

@media (max-width: 360px) {
    .envelope { width: 240px; height: 155px; }
    .envelope-flap {
        border-left-width: 120px;
        border-right-width: 120px;
        border-top-width: 82px;
    }
    .envelope-body::before { border-right-width: 120px; }
    .envelope-body::after  { border-left-width: 120px; }
}
