* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    height: 100vh;
    background: radial-gradient(circle at center, #0a0e1a 0%, #000 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Crimson Text', serif;
    color: #f5e6c4;
    overflow: hidden;
}

/* Starry night background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(2px 2px at 20% 30%, white, transparent),
        radial-gradient(2px 2px at 60% 70%, white, transparent),
        radial-gradient(1px 1px at 50% 50%, white, transparent),
        radial-gradient(1px 1px at 80% 10%, white, transparent),
        radial-gradient(2px 2px at 90% 60%, white, transparent),
        radial-gradient(1px 1px at 33% 80%, white, transparent),
        radial-gradient(1px 1px at 70% 40%, white, transparent);
    background-size: 200% 200%;
    background-position: 0% 0%;
    animation: twinkle 8s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(1px 1px at 15% 20%, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 40% 60%, rgba(255,255,255,0.6), transparent),
        radial-gradient(2px 2px at 75% 35%, rgba(255,255,255,0.7), transparent),
        radial-gradient(1px 1px at 25% 75%, rgba(255,255,255,0.5), transparent),
        radial-gradient(1px 1px at 85% 80%, rgba(255,255,255,0.6), transparent),
        radial-gradient(2px 2px at 45% 15%, rgba(255,255,255,0.8), transparent),
        radial-gradient(ellipse at 20% 20%, rgba(46, 92, 138, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(148, 107, 84, 0.1) 0%, transparent 50%);
    background-size: 250% 250%;
    animation: twinkle 10s ease-in-out infinite reverse;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Remove or comment out the old stars classes */
.stars, .stars2, .stars3 {
    display: none;
}

/* Fog effect */
.fog-container {
    position: fixed;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.fog {
    position: absolute;
    bottom: -50px;
    left: -50%;
    width: 200%;
    height: 200px;
    background: linear-gradient(to top, 
        rgba(14, 26, 64, 0.3) 0%,
        rgba(46, 92, 138, 0.15) 50%,
        transparent 100%);
    animation: fogMove 30s ease-in-out infinite;
    filter: blur(15px);
}

.fog-delayed {
    animation-delay: 15s;
    animation-duration: 40s;
}

@keyframes fogMove {
    0%, 100% { transform: translateX(0%) translateY(0px); }
    50% { transform: translateX(-20%) translateY(-30px); }
}

/* Floating candles */
.candle {
    position: fixed;
    width: 8px;
    height: 60px;
    background: linear-gradient(to bottom, #f4e8d0 0%, #946b54 100%);
    border-radius: 4px;
    pointer-events: none;
    opacity: 0.6;
    animation: floatCandle 8s ease-in-out infinite;
}

.candle::before {
    content: '🕯️';
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
    filter: drop-shadow(0 0 10px rgba(148, 107, 84, 0.8));
}

.candle1 {
    top: 10%;
    left: 15%;
    animation-delay: 0s;
}

.candle2 {
    top: 20%;
    right: 20%;
    animation-delay: 2s;
}

.candle3 {
    top: 60%;
    left: 10%;
    animation-delay: 4s;
}

@keyframes floatCandle {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-30px); }
}

.container {
    width: 100%;
    max-width: 428px;
    perspective: 1500px;
    padding: 20px;
    position: relative;
    z-index: 10;
}

/* Envelope wrapper */
.envelope-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1.6;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

.envelope-wrapper:active {
    transform: scale(0.98);
}

.envelope {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #946b54 0%, #7a5a47 100%);
    border: 3px solid #0e1a40;
    box-shadow: 
        0 20px 60px rgba(14, 26, 64, 0.8),
        inset 0 1px 0 rgba(148, 107, 84, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.5);
    transform-style: preserve-3d;
}

.paper-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(14, 26, 64, 0.05) 2px,
            rgba(14, 26, 64, 0.05) 4px
        );
    pointer-events: none;
    opacity: 0.3;
}

/* Envelope flap */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 52%;
    background: linear-gradient(135deg, #a67c52 0%, #946b54 100%);
    border-left: 3px solid #0e1a40;
    border-right: 3px solid #0e1a40;
    transform-origin: top center;
    clip-path: polygon(0 0, 50% 100%, 100% 0);
    z-index: 3;
    transform-style: preserve-3d;
    transition: transform 1.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 
        0 10px 30px rgba(14, 26, 64, 0.5),
        inset 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.flap-shadow {
    position: absolute;
    bottom: 0;
    left: 10%;
    width: 80%;
    height: 20px;
    background: radial-gradient(ellipse at center, rgba(14, 26, 64, 0.4) 0%, transparent 70%);
    filter: blur(5px);
}

.envelope-wrapper.open .envelope-flap {
    transform: rotateX(-180deg);
}

.wax-seal {
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    height: 70px;
    background: radial-gradient(circle at 30% 30%, #2e5c8a 0%, #0e1a40 50%, #05050a 100%);
    border-radius: 50%;
    border: 4px solid #946b54;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    transition: all 0.6s ease;
    box-shadow: 
        0 8px 25px rgba(14, 26, 64, 0.9),
        inset 0 2px 5px rgba(148, 107, 84, 0.3),
        inset 0 -2px 5px rgba(0, 0, 0, 0.5);
    transform-style: preserve-3d;
}

.wax-seal::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: radial-gradient(circle at center, transparent 60%, rgba(46, 92, 138, 0.4) 100%);
    animation: ravenclawGlow 3s ease-in-out infinite;
}

@keyframes ravenclawGlow {
    0%, 100% { 
        opacity: 0.5; 
        transform: scale(1);
        filter: drop-shadow(0 0 20px rgba(46, 92, 138, 0.3));
    }
    50% { 
        opacity: 1; 
        transform: scale(1.1);
        filter: drop-shadow(0 0 30px rgba(148, 107, 84, 0.5));
    }
}

.wax-drip {
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 20px;
    background: radial-gradient(ellipse at center, #0e1a40 0%, transparent 70%);
    border-radius: 50%;
    filter: blur(2px);
    opacity: 0.6;
}

.seal-letter {
    font-family: 'Cinzel', serif;
    font-size: 40px;
    font-weight: 700;
    color: #946b54;
    text-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.8),
        0 0 10px rgba(148, 107, 84, 0.6);
    z-index: 2;
}

.seal-shine {
    position: absolute;
    top: 15%;
    left: 25%;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, rgba(148, 107, 84, 0.5) 0%, transparent 70%);
    border-radius: 50%;
    filter: blur(3px);
}

.envelope-wrapper.open .wax-seal {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0) rotate(180deg);
    transition: all 0.8s ease;
}

/* Letter */
.letter {
    margin-top:20px;
    position: absolute;
    top: 8%;
    left: 4%;
    width: 92%;
    height: 88%;
    background: linear-gradient(135deg, #f5f0e8 0%, #e8dcc4 100%);
    padding: 0;
    box-shadow: 
        0 10px 40px rgba(14, 26, 64, 0.6),
        inset 0 1px 0 rgba(148, 107, 84, 0.3);
    transform: translateY(0) scale(0.95);
    opacity: 0;
    transition: all 1s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 2;
    overflow: hidden;
    border: 2px solid #946b54;
}

.envelope-wrapper.open .letter {
    transform: translateY(-30px) scale(1);
    opacity: 1;
    transition-delay: 0.6s;
}

/* Close button */
.letter::before {
    content: '✕';
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    color: #0e1a40;
    cursor: pointer;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(148, 107, 84, 0.2);
}

.envelope-wrapper.open .letter::before {
    opacity: 1;
    transition-delay: 1.2s;
}

.letter::before:hover {
    background: rgba(46, 92, 138, 0.3);
}

.letter-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 30px,
            rgba(14, 26, 64, 0.03) 30px,
            rgba(14, 26, 64, 0.03) 31px
        );
    pointer-events: none;
    opacity: 0.4;
}

.letter-content-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 30px 20px;
    overflow-y: auto;
    z-index: 1;
}

/* Letter header */
.letter-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    position: relative;
}

.hogwarts-emblem {
    margin-bottom: 15px;
}

.emblem-shield {
    display: inline-block;
    width: 120px;
    height: 120px;
    background-image: url('../images/42.jpg');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 10px;
    box-shadow: 
        0 4px 15px rgba(14, 26, 64, 0.5),
        inset 0 1px 3px rgba(148, 107, 84, 0.3),
        0 0 20px rgba(46, 92, 138, 0.3);
    position: relative;
    overflow: hidden;
    padding: 8px;
    background-color: #f5f0e8;
}
/* Remove the house-crest or hide it since we're using the image */
.house-crest {
    display: none;
}

/* Optional: Add a subtle overlay effect to the emblem */
.emblem-shield::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(148, 107, 84, 0.1) 0%, rgba(14, 26, 64, 0.1) 100%);
    pointer-events: none;
}

/* Optional: Add a shine effect */
.emblem-shield::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 70%
    );
    animation: shine 3s ease-in-out infinite;
}

@keyframes shine {
    0%, 100% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }
    50% {
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

.letter-title {
    font-family: 'Cinzel', serif;
    font-size: 26px;
    color: #2c1810;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.divider-line {
    width: 60%;
    height: 2px;
    background: linear-gradient(to right, transparent, #0e1a40, #946b54, #0e1a40, transparent);
    margin: 15px auto;
    position: relative;
}

.divider-line::before,
.divider-line::after {
    content: '◆';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #946b54;
    font-size: 8px;
}

.divider-line::before {
    left: -10px;
}

.divider-line::after {
    right: -10px;
}

.letter-subtitle {
    font-size: 13px;
    color: #0e1a40;
    font-style: italic;
    letter-spacing: 1px;
}

/* Letter content */
.letter-content {
    color: #2c1810;
    line-height: 1.9;
    font-size: 15px;
    text-align: justify;
}

.letter-content p {
    margin-bottom: 20px;
    text-indent: 30px;
}

.salutation {
    font-size: 18px;
    margin-bottom: 25px;
    color: #0e1a40;
    font-weight: 600;
    text-indent: 0 !important;
}

.closing {
    margin-top: 40px;
    text-align: right;
    position: relative;
}

.closing-text {
    font-style: italic;
    color: #2c1810;
    margin-bottom: 10px;
    text-indent: 0 !important;
}

.signature {
    font-family: 'Brush Script MT', 'Lucida Handwriting', cursive;
    font-size: 32px;
    color: #0e1a40;
    margin-top: 5px;
    text-indent: 0 !important;
    filter: drop-shadow(0 1px 2px rgba(148, 107, 84, 0.3));
}

.ink-splatter {
    position: absolute;
    bottom: -10px;
    right: 20px;
    width: 30px;
    height: 30px;
    background: radial-gradient(circle, rgba(14, 26, 64, 0.2) 0%, transparent 70%);
    border-radius: 50%;
    filter: blur(2px);
}

/* Scrollbar */
.letter-content-wrapper::-webkit-scrollbar {
    width: 8px;
}

.letter-content-wrapper::-webkit-scrollbar-track {
    background: rgba(232, 220, 196, 0.5);
    border-radius: 4px;
}

.letter-content-wrapper::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #0e1a40, #946b54);
    border-radius: 4px;
    border: 1px solid #0e1a40;
}

.letter-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(to bottom, #2e5c8a, #a67c52);
}

/* Instruction */
.instruction {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #946b54;
    font-size: 15px;
    text-align: center;
    opacity: 1;
    transition: opacity 0.6s ease;
    text-shadow: 
        0 0 10px rgba(148, 107, 84, 0.8),
        0 2px 4px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(46, 92, 138, 0.5);
    z-index: 5;
    pointer-events: none;
    font-family: 'Cinzel', serif;
    letter-spacing: 1px;
}

.envelope-wrapper.open .instruction {
    opacity: 0;
}

.sparkle {
    display: inline-block;
    animation: sparkleAnimation 2s ease-in-out infinite;
}

/* Letter link */
.letter-link {
    margin-top: 20px;
    text-decoration: none;
    color: #946b54;
    font-family: 'Cinzel', serif;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 1px;
    text-shadow: 
        0 0 10px rgba(148, 107, 84, 0.8),
        0 0 20px rgba(46, 92, 138, 0.5);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

.letter-link:hover {
    color: #2e5c8a;
    transform: scale(1.05);
}

@keyframes sparkleRotate {
    0%, 100% { transform: rotate(0deg) scale(1); opacity: 0.7; }
    50% { transform: rotate(180deg) scale(1.2); opacity: 1; }
}

.sparkle:first-child {
    animation-delay: 0s;
}

.sparkle:last-child {
    animation-delay: 1s;
}

@keyframes sparkleAnimation {
    0%, 100% { 
        opacity: 0.4;
        transform: scale(0.8) rotate(0deg);
        filter: drop-shadow(0 0 3px rgba(148, 107, 84, 0.6));
    }
    50% { 
        opacity: 1;
        transform: scale(1.2) rotate(180deg);
        filter: drop-shadow(0 0 8px rgba(46, 92, 138, 0.8));
    }
}

.instruction-text {
    margin: 0 8px;
}

/* Responsive adjustments */
@media (max-width: 428px) {
    .letter-content {
        font-size: 14px;
    }
    
    .letter-title {
        font-size: 22px;
    }
    
    .signature {
        font-size: 28px;
    }
}