:root {
    --bg-color: #FFF7FA;
    --primary-pink: #F7A8C4;
    --secondary-pink: #FFD6E3;
    --accent-pink: #E98BA8;
    --text-color: #6A5160;
    --card-bg: #FFFFFF;
    
    --font-thai: 'Noto Sans Thai Looped', sans-serif;
    --font-serif: 'Noto Serif KR', serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-color);
    font-family: var(--font-thai);
    color: var(--text-color);
    font-size: 15px;
    letter-spacing: -0.01em;
}

.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 1.2s ease, visibility 1.2s;
    z-index: 1;
    padding: 24px;
    text-align: center;
}

.scene.active {
    opacity: 1;
    visibility: visible;
    z-index: 2;
}

#cinematic-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000000;
    z-index: 999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#cinematic-overlay.overlay-visible {
    opacity: 1;
}

#countdown-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000000;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s;
}

#countdown-layer.countdown-visible {
    opacity: 1;
    visibility: visible;
}

#countdown-number {
    font-family: var(--font-serif);
    font-size: 5rem;
    color: var(--secondary-pink);
    opacity: 0;
    transform: scale(0.5);
}

.animate-number {
    animation: zoomPulseNumber 1s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes zoomPulseNumber {
    0% { transform: scale(0.4); opacity: 0; filter: blur(4px); }
    30% { transform: scale(1.1); opacity: 1; filter: blur(0); }
    80% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.4); opacity: 0; filter: blur(2px); }
}

/* เลเยอร์ตัวเลขอายุระเบิดกลายเป็นพลุ/เบลนหาย */
#age-blast-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.92);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease, visibility 0.6s;
}

#age-blast-overlay.age-blast-visible {
    opacity: 1;
    visibility: visible;
}

#blast-number-text {
    font-family: var(--font-serif);
    font-size: 9rem;
    font-weight: bold;
    color: var(--secondary-pink);
    text-shadow: 0 0 30px var(--accent-pink);
    opacity: 0;
    transform: scale(0.3);
}

#blast-sub-caption {
    font-family: var(--font-thai);
    font-size: 1.3rem;
    color: #FFF;
    margin-top: 20px;
    opacity: 0;
    transform: translateY(20px);
    text-align: center;
    padding: 0 20px;
}

.animate-age-pop-blast {
    animation: agePopBlastEffect 2.8s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.animate-caption-fade-in {
    animation: captionFadeEffect 2.8s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes agePopBlastEffect {
    0% { transform: scale(0.3); opacity: 0; filter: blur(10px); }
    25% { transform: scale(1.2); opacity: 1; filter: blur(0px); }
    60% { transform: scale(1.0); opacity: 1; filter: blur(0px); }
    85% { transform: scale(2.5); opacity: 0.3; filter: blur(15px); }
    100% { transform: scale(3.5); opacity: 0; filter: blur(30px); }
}

@keyframes captionFadeEffect {
    0% { opacity: 0; transform: translateY(20px); }
    25% { opacity: 1; transform: translateY(0); }
    75% { opacity: 1; filter: blur(0px); }
    100% { opacity: 0; filter: blur(10px); }
}

#surprise-burst-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 99;
    overflow: hidden;
}

.burst-heart {
    position: absolute;
    width: 20px;
    height: 20px;
    fill: var(--accent-pink);
    opacity: 0;
    transform: scale(0);
    animation: heartFlyOut var(--duration) cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes heartFlyOut {
    0% {
        top: var(--start-y);
        left: var(--start-x);
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        top: calc(var(--start-y) + var(--target-y));
        left: calc(var(--start-x) + var(--target-x));
        transform: translate(-50%, -50%) scale(var(--scale)) rotate(var(--rotate));
        opacity: 0;
    }
}

.story-text {
    font-weight: 400;
    font-size: 1.25rem;
    line-height: 1.9;
    margin-top: 30px;
    margin-bottom: 25px;
    color: var(--text-color);
}

.highlight-name {
    font-weight: 500;
    font-family: var(--font-serif);
    font-size: 1.4rem;
    color: var(--accent-pink);
    border-bottom: 1px solid var(--secondary-pink);
    padding-bottom: 2px;
}

.btn-premium {
    background-color: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--secondary-pink);
    padding: 13px 38px;
    font-family: var(--font-thai);
    font-size: 0.95rem;
    font-weight: 400;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(106, 81, 96, 0.04);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    outline: none;
}

.btn-premium:active {
    transform: scale(0.96);
    background-color: var(--bg-color);
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loading-text {
    font-size: 0.95rem;
    opacity: 0.6;
    animation: pulseFade 2s infinite ease-in-out;
}

.envelope-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.envelope-wrapper {
    position: relative;
    width: 280px;
    height: 200px;
}

.exclamation-mark {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%) scale(0);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
}

.exclamation-mark.pop-out {
    transform: translateX(-50%) scale(1);
    opacity: 1;
}

.shake-element {
    animation: quickShake 0.4s ease-in-out;
}

.cake-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.cake-wrapper {
    transform: translateY(100px);
    opacity: 0;
    transition: transform 2s cubic-bezier(0.16, 1, 0.3, 1), opacity 2s;
}

.cake-wrapper.slide-up {
    transform: translateY(0);
    opacity: 1;
}

.mic-status {
    font-size: 0.85rem;
    margin-top: 15px;
    opacity: 0.6;
    font-weight: 300;
}

.fallback-hidden {
    display: none;
}

.wish-container {
    width: 100%;
    max-width: 330px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.input-wrapper {
    width: 100%;
    position: relative;
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(106, 81, 96, 0.04);
    margin-bottom: 24px;
    border: 1px solid rgba(255, 214, 227, 0.4);
    transition: transform 2s cubic-bezier(0.6, -0.28, 0.735, 0.045), opacity 1.5s ease, filter 1.5s ease;
    transform-origin: center center;
}

/* ช่องกรอกอายุดีไซน์เรียบหรูโทนสีพาสเทล */
.age-input-block {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--secondary-pink);
    font-size: 0.9rem;
}

.age-input-block input {
    width: 65px;
    padding: 5px 10px;
    border: 1px solid var(--secondary-pink);
    border-radius: 8px;
    outline: none;
    font-family: var(--font-thai);
    color: var(--text-color);
    text-align: center;
    background-color: var(--bg-color);
}

.wish-paper-fly-up {
    transform: translateY(-100vh) scale(0.01) rotate(720deg);
    opacity: 0;
    filter: blur(4px);
}

#wish-input {
    width: 100%;
    height: 90px;
    border: none;
    resize: none;
    outline: none;
    background: transparent;
    font-family: var(--font-thai);
    color: var(--text-color);
    font-size: 0.95rem;
    line-height: 1.7;
}

#wish-input::placeholder {
    color: var(--text-color);
    opacity: 0.35;
}

.character-counter {
    position: absolute;
    bottom: 12px;
    right: 16px;
    font-size: 0.75rem;
    opacity: 0.4;
}

#star-transformation-space {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.transforming-star {
    position: absolute;
    left: 50%;
    bottom: 120px;
    transform: translateX(-50%) scale(0);
    fill: var(--accent-pink);
    opacity: 0;
    animation: starAscendAndBurst 2.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes starAscendAndBurst {
    0% { bottom: 120px; transform: translateX(-50%) scale(0) rotate(0deg); opacity: 0; }
    30% { opacity: 1; transform: translateX(-50%) scale(1.5) rotate(180deg); }
    75% { bottom: 65vh; transform: translateX(-50%) scale(1.8) rotate(540deg); opacity: 1; filter: drop-shadow(0 0 8px var(--primary-pink)); }
    90% { transform: translateX(-50%) scale(2.3) rotate(640deg); opacity: 1; }
    100% { bottom: 65vh; transform: translateX(-50%) scale(0) rotate(720deg); opacity: 0; }
}

#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 999;
}

.wish-particle-node {
    position: absolute;
    border-radius: 50%;
    background-color: var(--primary-pink);
    opacity: 0.6;
    pointer-events: none;
    animation: driftUpwards var(--d) linear forwards;
}

@keyframes driftUpwards {
    0% { transform: translateY(70vh) translateX(0) scale(0); opacity: 0; }
    10% { opacity: 0.8; }
    90% { opacity: 0.5; }
    100% { transform: translateY(-20vh) translateX(var(--x-drift)) scale(1); opacity: 0; }
}

/* เลเยอร์ฉากหลังฝนของฉากการ์ดอวยพร */
#card-background-celebration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-float-asset {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    animation: floatingBackgroundItems var(--speed) linear infinite;
}

/* คอนเทนเนอร์ข้อความตัวเลข/เค้ก ในฝนดาวตกฉากหลัง */
.bg-float-text-asset {
    position: absolute;
    font-family: var(--font-serif);
    font-weight: bold;
    color: var(--primary-pink);
    pointer-events: none;
    opacity: 0;
    animation: floatingBackgroundItems var(--speed) linear infinite;
}

@keyframes floatingBackgroundItems {
    0% { transform: translateY(110vh) translateX(0) rotate(0deg); opacity: 0; }
    10% { opacity: var(--max-opacity); }
    90% { opacity: var(--max-opacity); }
    100% { transform: translateY(-10vh) translateX(var(--drift-x)) rotate(var(--target-rot)); opacity: 0; }
}

.card-cinematic-space {
    position: relative;
    width: 100%;
    max-width: 345px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2;
}

.envelope-background-system {
    position: absolute;
    width: 270px;
    height: 190px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.85);
    opacity: 0;
    transition: all 1.8s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 1;
}

.envelope-background-system.zoom-back {
    opacity: 1;
    transform: translate(-50%, -20%) scale(0.95);
}

.letter-card {
    width: 100%;
    background-color: var(--card-bg);
    border-radius: 24px;
    box-shadow: 0 16px 45px rgba(106, 81, 96, 0.08);
    padding: 28px 22px;
    z-index: 2;
    transform: translateY(120px) scale(0.85);
    opacity: 0;
    transition: transform 1.8s cubic-bezier(0.25, 1, 0.5, 1), opacity 1.8s;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.letter-card.slide-extract {
    transform: translateY(-8%) scale(1);
    opacity: 1;
}

.card-inner-scroll {
    overflow-y: auto;
    width: 100%;
}

.card-header-tag {
    font-family: var(--font-serif);
    font-size: 0.85rem;
    font-weight: 400;
    letter-spacing: 0.2em;
    color: var(--accent-pink);
    margin-bottom: 15px;
    opacity: 0.8;
}

.photo-frame-container {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 18px;
}

.photo-emulsion-base {
    width: 145px; 
    height: 145px;
    border-radius: 50%;
    padding: 6px;
    border: 1px solid var(--secondary-pink);
    background-color: var(--bg-color);
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(233, 139, 168, 0.15);
    transform: scale(0.7);
    opacity: 0;
    transition: transform 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.8s, opacity 1s ease 0.8s;
}

.letter-card.slide-extract .photo-popup-effect {
    transform: scale(1);
    opacity: 1;
}

.photo-emulsion-base img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.card-title {
    font-family: var(--font-serif);
    font-size: 1.35rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-color);
}

.card-divider {
    margin: 14px 0;
}

.card-message {
    font-size: 0.95rem;
    line-height: 1.8;
    opacity: 0.85;
    font-weight: 300;
    text-align: center;
    margin-bottom: 15px;
}

/* ดีไซน์พื้นที่แสดงผลคำอธิษฐานพิเศษท้ายการ์ดตามสั่ง */
.card-wish-reveal-area {
    margin-top: 15px;
    padding: 12px 16px;
    background-color: var(--bg-color);
    border-radius: 12px;
    border-left: 3px solid var(--accent-pink);
    text-align: left;
}

.wish-reveal-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent-pink);
    margin-bottom: 4px;
}

.wish-reveal-text {
    font-size: 0.9rem;
    line-height: 1.6;
    font-style: italic;
    opacity: 0.8;
}

.close-btn-space {
    margin-top: 15px;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.8s ease 1s;
}

.close-btn-space.visible {
    opacity: 1;
}

.ending-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    max-width: 80%;
}

.ending-text-line {
    font-family: var(--font-thai);
    font-size: 1rem;
    font-weight: 300;
    line-height: 1.8;
    color: var(--text-color);
    opacity: 0;
    transform: translateY(10px);
    animation: simpleFadeInUp 2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.btn-close-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 1.5s ease, visibility 1.5s, transform 1.5s cubic-bezier(0.25, 1, 0.5, 1);
}

.btn-close-hidden.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

@keyframes simpleFadeInUp {
    100% { opacity: 0.9; transform: translateY(0); }
}

@keyframes pulseFade {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.9; }
}

@keyframes quickShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.dynamic-float {
    animation: floatingEffect 3s infinite ease-in-out;
}

@keyframes floatingEffect {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(15deg); }
}

.pulse-glow {
    animation: globalGlow 2s infinite ease-in-out;
    transform-origin: 100px 53px;
}

@keyframes globalGlow {
    0%, 100% { transform: scale(0.95); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 0.9; }
}

.flicker-flame {
    animation: torchFlicker 0.15s infinite alternate ease-in-out;
    transform-origin: 100px 55px;
}

@keyframes torchFlicker {
    0% { transform: scaleX(0.96) rotate(-1deg); }
    100% { transform: scaleX(1.04) rotate(1.5deg); }
}