:root {
    --night-bg: #0b101c;
    --lantern-glow: rgba(255, 200, 50, 0.8);
    --lantern-red: #cc3333;
    --paper-white: #fdf5e6;
    --parchment-border: #d4af37;
    --text-color: #eee;
    --memorial-gold: #d4af37; /* Shared Gold */
    --memorial-red: #8b0000;  /* Shared Red */
    --gold-hover: #e5c05a;
}

/* Ensure HTML and Body occupy the viewport exactly */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent body-level scrolling */
    background-color: var(--night-bg);
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
    font-size: 18px;
}

/* Base scrolling layer for the site content */
.overlay {
    position: absolute;
    inset: 0; /* Cover the whole body */
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Twinkling Stars - Background layer */
#stars-container {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    opacity: 0;
    animation: twinkle var(--duration) infinite ease-in-out;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.1; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* Top Title */
.site-title {
    font-family: 'Inter', sans-serif;
    text-transform: uppercase;
    letter-spacing: 4px;
    font-size: 0.9rem;
    opacity: 0.7;
    margin-bottom: 20px;
    color: white;
}

/* Action Button - STRICT UNIFORM DESIGN */
.btn-primary {
    background-color: var(--memorial-gold) !important;
    color: var(--memorial-red) !important;
    border: 2px solid var(--memorial-red) !important;
    padding: 12px 30px !important;
    cursor: pointer !important;
    font-family: inherit !important;
    font-weight: 700 !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6) !important;
    transition: 0.3s !important;
    pointer-events: auto !important;
    margin-top: 20px !important;
    display: inline-block !important;
}

.btn-primary:hover {
    background-color: var(--gold-hover) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8) !important;
}

.btn-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.btn-sep {
    width: 100%;
    height: 1px;
    background: rgba(139, 0, 0, 0.3);
    margin: 8px 0;
}

.btn-primary .zh { font-size: 1.4rem !important; }
.btn-primary .en { font-size: 1rem !important; opacity: 1 !important; }

#sky-container {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
}

header, footer {
    pointer-events: auto;
}

.title-section {
    pointer-events: auto;
    padding: 20px 20px;
}

.intro-box {
    pointer-events: auto;
    display: flex;
    max-width: 900px;
    margin: 20px auto 40px auto;
    gap: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 25px;
    border-radius: 12px;
    border: 1px solid rgba(255, 215, 0, 0.2);
}

.intro-column {
    flex: 1;
    text-align: left;
    line-height: 1.6;
}

.intro-column p {
    margin: 0;
    font-size: 1.2rem;
    color: #fff;
}

.name-highlight {
    color: var(--memorial-gold);
}

/* Modal - VIEWPORT CENTERING FIX */
.modal {
    display: none;
    position: fixed;
    inset: 0; /* Ensures full screen coverage */
    z-index: 10000;
    background-color: rgba(0,0,0,0.85);
    pointer-events: auto;
    
    /* Strong Centering */
    display: none; 
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.modal-content {
    background-color: #fcf5e5;
    background-image: url("https://www.transparenttextures.com/patterns/handmade-paper.png");
    padding: 0 20px;
    
    /* REFINED: Drive width by photo, fallback to min-width */
    display: flex;
    flex-direction: column;
    width: fit-content;
    min-width: 50vw;
    max-width: 75vw;
    max-height: 95vh;
    
    position: relative;
    color: #2c1e14;
    font-size: 1.2rem;
    pointer-events: auto;
    border: 1px solid #dcd0c0;
    box-shadow: 2px 2px 20px rgba(0,0,0,0.4);
    border-radius: 2px;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Close Button */
.close-button {
    position: absolute;
    right: 15px;
    top: 5px;
    font-size: 35px;
    font-weight: 300;
    cursor: pointer;
    color: #8b4513;
    line-height: 1;
    z-index: 10100;
    transition: 0.2s;
    background: none;
    border: none;
}

.close-button:hover {
    color: #cc0000;
    transform: scale(1.1);
}

textarea {
    width: 100%;
    height: 150px;
    padding: 10px;
    border: 1px solid var(--memorial-gold);
    background: rgba(255,255,255,0.5);
    font-family: inherit;
    font-size: 1.1rem;
    box-sizing: border-box;
    display: block;
    margin: 15px 0;
}

#view-content {
    font-size: 1.25rem;
    line-height: 1.1;
    white-space: pre-wrap;
    margin: 0;
    padding: 40px 0 10px 0; /* Space for close button */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.view-image {
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 55vh; 
    object-fit: contain;
    display: block;
    border: none;
    margin-top: 25px;
    margin-bottom: 25px;
}

#view-text-container {
    width: 0;
    min-width: 100%;
}

/* Portrait photo height override */
.is-portrait .view-image {
    max-height: 75vh;
}

#view-meta {
    font-size: 0.5rem;
    color: #705e4a;
    font-style: italic;
    margin: 0 -20px;
    padding: 5px 20px;
    text-align: right;
    background: rgba(0,0,0,0.05);
}

/* Lanterns */
.lantern {
    position: absolute;
    width: 65px;
    height: 90px;
    background: linear-gradient(to bottom, #ffcc33 0%, #ff6600 100%);
    border-radius: 40% 40% 5px 5px / 20% 20% 5px 5px;
    clip-path: polygon(15% 100%, 85% 100%, 100% 20%, 90% 10%, 75% 3%, 50% 0%, 25% 3%, 10% 10%, 0% 20%);
    cursor: pointer;
    box-shadow: 0 0 35px rgba(255, 102, 0, 0.5);
    animation: floatUp 25s linear infinite, sway 4s ease-in-out infinite alternate;
    z-index: 60;
    opacity: 0.95;
    pointer-events: auto !important;
}

.lantern::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 15%;
    width: 70%;
    height: 3px;
    background: #2b1d0e;
}

@keyframes floatUp { from { bottom: -100px; } to { bottom: 110%; } }
@keyframes sway { from { transform: translateX(calc(-1 * var(--sway-range, 25px))); } to { transform: translateX(var(--sway-range, 25px)); } }

.scrollbar-custom::-webkit-scrollbar { width: 8px; }
.scrollbar-custom::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.05); }
.scrollbar-custom::-webkit-scrollbar-thumb { background: var(--memorial-gold); border-radius: 4px; }

header { text-align: center; color: white; }
.title-section h1.zh { font-family: 'Ma Shan Zheng', cursive; font-size: 5rem; margin: 0 0 20px 0; color: #ffd700; text-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }
.title-section h1.en { font-family: 'Inter', sans-serif; font-size: 2.5rem; margin: 0 0 5px 0; letter-spacing: 1px; font-weight: 700; }
.wavy-divider { width: 60px; height: 10px; margin: 10px auto; color: rgba(255, 215, 0, 0.4); }
.wavy-divider svg { width: 100%; height: 100%; }
.dates { font-size: 1.3rem; opacity: 0.9; margin-bottom: 40px; }
footer { padding: 20px; text-align: center; color: white; opacity: 0.6; font-size: 0.9rem; pointer-events: auto; }

#admin-trigger { pointer-events: auto !important; padding: 20px; margin: -20px; }
#admin-logout { background: none; border: 1px solid rgba(255,255,255,0.3); color: rgba(255,255,255,0.6); padding: 5px 15px; cursor: pointer; font-family: inherit; font-size: 0.8rem; margin-top: 10px; transition: 0.3s; border-radius: 4px; }
#admin-logout:hover { background: rgba(255,255,255,0.1); color: white; }

.delete-btn { background: var(--memorial-red); border: none; color: white; padding: 8px 16px; cursor: pointer; font-size: 0.9rem; margin: 10px 0; display: inline-block; border-radius: 4px; }
.delete-btn:hover { background: #a50000; color: white; }

.modal-header-text { margin: 0 0 15px 0; font-size: 1.5rem; color: #8b4513; display: block; padding-top: 15px; }
.modal-header-text .zh, .modal-header-text .en { display: inline !important; }
.optional-text { font-size: 0.8rem; font-style: italic; opacity: 0.7; margin-left: 5px; }
#image { margin-bottom: 15px; }

.row-group { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-top: 15px; padding-bottom: 15px; flex-wrap: wrap; }
.file-input-wrapper { flex: 1; min-width: 150px; }
.btn-submit { margin-top: 10px !important; padding: 10px 20px !important; white-space: nowrap; flex-shrink: 0; }
.btn-submit .zh, .btn-submit .en { display: inline !important; font-size: 1rem !important; opacity: 1 !important; }

/* MOBILE OVERRIDES */
@media (max-width: 768px) {
    body { font-size: 16px !important; }
    .intro-box { flex-direction: column !important; padding: 15px !important; margin: 10px !important; gap: 15px !important; }
    .intro-column p { font-size: 1.1rem !important; }
    .title-section h1.zh { font-size: 3.5rem !important; }
    .title-section h1.en { font-size: 1.8rem !important; }
    .dates { font-size: 1.1rem !important; margin-bottom: 25px !important; }
    
    /* Align button width to intro-box on mobile */
    .btn-primary {
        display: block !important;
        width: auto !important;
        margin-left: 10px !important;
        margin-right: 10px !important;
    }

    /* Tad bigger lanterns on mobile (adjusted scale) */
    .lantern { width: 52px !important; height: 72px !important; }
    .lantern::after { height: 2px !important; }
}

@media (max-width: 600px) {
    .modal-content { 
        width: fit-content !important; 
        min-width: 80vw !important; 
        max-width: 90vw !important; 
        max-height: 95vh !important; 
        padding: 0 15px !important; 
    }
    .view-image { width: auto !important; max-width: 100% !important; max-height: 35vh !important; margin-top: 25px !important; margin-bottom: 25px !important; }
    .is-portrait .view-image { max-height: 55vh !important; }
    #view-text-container { width: 0 !important; min-width: 100% !important; }
    #view-content { font-size: 1.15rem !important; }
    .title-section h1.zh { font-size: 2.8rem !important; }
    .title-section h1.en { font-size: 1.5rem !important; }
    .site-title { letter-spacing: 2px !important; font-size: 0.8rem !important; }
    .dates { font-size: 1rem !important; }
}
