:root {
    --primary-red: #D9342F;
    --dark-red: #a82420;
    --gold: #F1C40F;
    --light-gold: #FFD700;
    --bg-color: #8E1E18;
    --text-color: #333;
    --paper-color: rgba(255, 255, 255, 0.92); /* Translucent for fireworks */
    --card-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    /* Starry Night Background */
    background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
    background-size: cover;
    color: var(--text-color);
    overflow: hidden; 
    height: 100vh;
    height: 100dvh; /* Mobile viewport fix */
    width: 100vw;
}

/* Fireworks Canvas - Ensure it's behind but visible */
#fireworks {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* Pages */
.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    transition: opacity 0.5s ease;
}

.hidden {
    display: none !important;
    opacity: 0;
}

/* Landing Page: Red Envelope */
#landing-page {
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent;
    z-index: 20; /* Above fireworks initially */
    overflow: hidden;
}

/* Starry Night Background on Body */
body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    /* Starry Night Background */
    background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
    background-size: cover;
    color: var(--text-color);
    overflow: hidden; 
    height: 100vh;
    height: 100dvh; /* Mobile viewport fix */
    width: 100vw;
}

/* Stars pseudo-element on body instead of landing-page */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 2px;
    background: white;
    box-shadow: 
        10vw 10vh 1px 0px #fff,
        20vw 80vh 1px 1px #fff,
        30vw 20vh 2px 0px #fff,
        40vw 50vh 1px 0px #fff,
        50vw 90vh 2px 1px #fff,
        60vw 10vh 1px 0px #fff,
        70vw 70vh 1px 1px #fff,
        80vw 30vh 2px 0px #fff,
        90vw 60vh 1px 0px #fff,
        5vw 95vh 1px 1px #fff,
        15vw 5vh 2px 0px #fff,
        25vw 45vh 1px 0px #fff,
        35vw 85vh 1px 1px #fff,
        45vw 15vh 2px 0px #fff,
        55vw 55vh 1px 0px #fff,
        65vw 25vh 2px 1px #fff,
        75vw 65vh 1px 0px #fff,
        85vw 35vh 1px 1px #fff,
        95vw 5vh 2px 0px #fff;
    opacity: 0.8;
    animation: twinkle 5s infinite linear;
    z-index: 0;
    pointer-events: none;
}

@keyframes twinkle {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Fallback for background image if user provides one */
#landing-page.has-bg-image {
    background-image: url('../images/bg.jpg');
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

.red-envelope-container {
    perspective: 1200px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.red-envelope {
    width: 320px;
    height: 500px;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    border-radius: 20px;
    position: relative;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid #eebb4d;
    transform-style: preserve-3d;
}

/* More detailed flap */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 180px;
    background: linear-gradient(to bottom, #a93226, #c0392b);
    border-radius: 0 0 50% 50%;
    z-index: 5;
    transform-origin: top;
    transition: transform 0.6s ease-in-out;
    border-bottom: 3px solid #eebb4d;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.envelope-flap.open {
    transform: rotateX(180deg);
    z-index: 1; /* Move behind front content when open */
}

.envelope-front {
    z-index: 6;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 100px;
    /* Subtle texture */
    background-image: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px);
    background-size: 20px 20px;
}

.horse-logo {
    width: 90px;
    height: 90px;
    background: linear-gradient(45deg, #f1c40f, #f39c12);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 44px;
    font-weight: bold;
    color: #c0392b;
    margin-bottom: 40px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3), inset 0 0 10px rgba(255,255,255,0.4);
    border: 3px solid #fff5c5;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.3);
}

.instruction {
    color: #fceabb;
    margin-bottom: 15px;
    font-size: 16px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    font-weight: 500;
}

#uidInput {
    padding: 12px;
    border-radius: 25px;
    border: 2px solid #eebb4d;
    text-align: center;
    margin-bottom: 25px;
    font-size: 16px;
    width: 75%;
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
    outline: none;
}

#uidInput:focus {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255,215,0,0.5);
}

#openBtn {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #f7dc6f, #d4ac0d);
    border: 4px solid #fcf3cf;
    color: #8e1e18;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

#openBtn:active {
    transform: scale(0.92);
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.error-msg {
    color: #fceabb;
    margin-top: 20px;
    font-size: 14px;
    height: 20px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Blessing Page - New Layout */
#blessing-page {
    background-color: transparent; /* Transparent to show fireworks */
    /* If fireworks are too bright, add a dark overlay here */
    background: rgba(0, 0, 0, 0.1); 
}

.scroll-container {
    height: 100%;
    width: 100%;
    overflow-y: scroll;
    scroll-snap-type: y mandatory; /* Enable scroll snapping */
    scroll-behavior: smooth;
}

.scroll-section {
    height: 100vh;
    height: 100dvh;
    width: 100%;
    scroll-snap-align: start; /* Snap to top of each section */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
}

.content-wrapper {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Optional: Entrance animation for content */
    animation: fadeInUp 0.8s ease-out;
}

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

/* Glass Card Effect for readability over fireworks */
.glass-card {
    background: var(--paper-color);
    border-radius: 15px;
    padding: 25px;
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255,255,255,0.6);
    width: 100%;
}

.header {
    text-align: center;
    margin-bottom: 25px;
}

.header h1 {
    font-size: 32px;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    font-weight: bold;
    letter-spacing: 2px;
}

.banner {
    background: linear-gradient(to right, #e74c3c, #c0392b);
    color: white;
    padding: 15px 30px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    border: 2px solid #f5b041;
}

.horse-icon {
    font-size: 30px;
    margin-right: 10px;
}

.card h3 {
    color: var(--primary-red);
    margin-bottom: 20px;
    border-bottom: 2px dashed #e6b0aa;
    padding-bottom: 10px;
    text-align: center;
    font-size: 20px;
}

.card p {
    line-height: 1.8;
    margin-bottom: 12px;
    font-size: 16px;
    color: #4a4a4a;
}

.highlight {
    color: #c0392b;
    font-weight: bold;
    font-size: 1.2em;
    margin: 0 3px;
    background: rgba(231, 76, 60, 0.1);
    padding: 0 5px;
    border-radius: 4px;
}

.memory-section {
    margin-top: 20px;
    background-color: #fff5f5;
    padding: 15px;
    border-radius: 10px;
    border-left: 4px solid var(--primary-red);
}

/* Expandable Content */
.expandable-content {
    position: relative;
    width: 100%;
}

.collapsed-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px !important;
    max-height: 4.8em; /* Fallback height constraint ~ 3 lines * 1.6 */
    white-space: pre-wrap; /* Preserve newlines and wrap text */
}

.expanded .collapsed-text {
    -webkit-line-clamp: unset !important;
    overflow: visible !important;
    max-height: none !important;
    display: block !important;
}

.read-more-btn {
    display: block;
    text-align: right;
    color: var(--primary-red);
    font-size: 14px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 5px;
    padding: 5px 0;
}

.read-more-btn:hover {
    text-decoration: underline;
}

.memory-section h4 {
    font-size: 14px;
    color: #999;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.blessing-content {
    font-size: 18px;
    line-height: 1.8;
    color: #333;
    text-align: justify;
}

/* Scroll Hint Arrow */
.scroll-hint {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    animation: bounce 2s infinite;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

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

/* Lucky Draw Styles Refined */
.lucky-draw-section {
    text-align: center;
    background: linear-gradient(135deg, #fff 0%, #fff0f0 100%);
    border: 4px solid #fdedec;
}

.lucky-title {
    font-size: 24px;
    color: var(--dark-red);
    margin-bottom: 25px;
    font-weight: bold;
    border-bottom: none;
}

.draw-btn {
    background: linear-gradient(to bottom, #e74c3c, #c0392b);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 20px;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 0 #922b21, 0 10px 20px rgba(0,0,0,0.2);
    transition: all 0.1s;
    font-weight: bold;
}

.draw-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #922b21, inset 0 2px 5px rgba(0,0,0,0.2);
}

.draw-result {
    font-size: 50px;
    color: #e74c3c;
    font-weight: 800;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.1);
}

.footer {
    position: absolute;
    bottom: 10px;
    width: 100%;
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 12px;
}

/* Hidden Easter Egg */
.detail-god {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.03); /* Almost invisible */
    user-select: all;
    z-index: 100;
    pointer-events: auto;
}

/* Code Copy Cursor */
.code {
    font-weight: bold;
    color: var(--primary-red);
    font-size: 1.2em;
    user-select: all;
    cursor: pointer;
    border-bottom: 1px dashed var(--primary-red);
}

.code:active {
    background-color: rgba(217, 52, 47, 0.1);
}

.copy-hint {
    font-size: 12px;
    color: #999;
    margin-top: 5px;
    display: block;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.modal-card {
    position: relative;
    width: 85%;
    max-width: 500px;
    max-height: 80vh;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1001;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--primary-red);
    font-size: 18px;
}

.close-modal {
    font-size: 28px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    text-align: justify;
    word-wrap: break-word;
}

/* View Full Text Button */
.view-full-btn {
    display: block;
    text-align: right;
    color: var(--primary-red);
    font-size: 14px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 5px;
    padding: 5px 0;
}

.view-full-btn:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    .red-envelope {
        width: 85vw;
        height: 60vh;
        max-height: 500px;
    }
    
    .header h1 {
        font-size: 28px;
    }
    
    .instruction {
        font-size: 14px;
    }

    #uidInput {
        width: 85%;
    }
}
