:root {
    --f1-red: #CC1E4A;
    --rb-navy: #061D42;
    --rb-yellow: #FFC72C;
    --daphne-purple: #5A3B8B;
    --daphne-light-purple: #9F8FEF;
    --daphne-green: #99CC33;
    --glass-bg: rgba(6, 29, 66, 0.7);
    --glass-border: rgba(255, 199, 44, 0.2);
}

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

html,
body {
    overflow-x: hidden;
    /* Strict overflow control */
    width: 100%;
    margin: 0;
    padding: 0;
    position: relative;
    /* Contain absolute elements */
}

body {
    background-color: var(--rb-navy);
    background-image: linear-gradient(135deg, #020b1c 0%, var(--rb-navy) 100%);
    color: white;
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
    transition: background-image 1.5s ease, background-color 1.5s ease;
}

body.daphne-mode {
    background-color: var(--daphne-purple);
    background-image: radial-gradient(circle at center, #2e1a47 0%, #000000 100%);
}

body.daphne-mode .racing-bg {
    filter: blur(8px) brightness(0.6);
    transition: filter 1.5s ease;
}

body.daphne-mode .container {
    border-color: var(--daphne-light-purple);
    background: rgba(42, 27, 71, 0.7);
    /* Daphne purple dark */
}

body.daphne-mode .subtitle {
    border-color: var(--daphne-green);
    color: var(--daphne-green);
}

body.daphne-mode .hero h1 {
    text-shadow:
        2px 2px 0px var(--daphne-green),
        -1px -1px 0 var(--daphne-purple);
}

/* Background Elements */
.racing-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

.track-line {
    position: absolute;
    height: 3px;
    width: 100%;
    background: linear-gradient(90deg, transparent, var(--f1-red), var(--rb-yellow), transparent);
    box-shadow: 0 0 15px var(--f1-red);
    opacity: 0.6;
}

.track-line:nth-child(1) {
    top: 15%;
    animation: scanline 4s linear infinite;
}

.track-line:nth-child(2) {
    top: 85%;
    animation: scanline 6s linear infinite reverse;
}

.f1-car {
    position: absolute;
    width: 250px;
    filter: drop-shadow(0 0 15px var(--daphne-green));
    z-index: -1;
    transform: translateX(120vw);
    /* Ensure they start off-screen right */
}

.car-1 {
    top: 10%;
    animation: race-left 6s linear infinite;
}

.car-2 {
    top: 40%;
    animation: race-left 9s linear infinite 2s;
    width: 180px;
    opacity: 0.5;
    filter: blur(2px);
}

.car-3 {
    top: 70%;
    animation: race-left 7s linear infinite 4s;
    width: 300px;
}

@keyframes race-left {
    from {
        transform: translateX(120vw);
    }

    to {
        transform: translateX(-400px);
    }
}

@keyframes scanline {
    from {
        transform: translateX(-100%);
    }

    to {
        transform: translateX(100%);
    }
}

/* Glassmorphism Card */
.container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 1.5rem 2rem;
    /* Reduced top/bottom padding */
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
    /* Contains the glow */
}

/* Glow efffect behind card */
.container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 199, 44, 0.15) 0%, transparent 60%);
    z-index: -1;
    animation: rotate-glow 20s linear infinite;
}

@keyframes rotate-glow {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Typography */
.rb-logo {
    width: 200px;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.2));
    transition: all 0.5s ease;
}

.daphne-full {
    height: 100%;
    max-height: 220px;
    /* Increased size */
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 5px 10px rgba(90, 59, 139, 0.5));
    animation: float 4s ease-in-out infinite;
    transform-origin: bottom center;
}

.rb-logo.hidden {
    opacity: 0;
    transform: translateY(-20px) scale(0.9);
}

.hero h1 {
    font-family: 'Racing Sans One', cursive;
    font-size: 3rem;
    color: white;
    font-style: italic;
    text-transform: uppercase;
    text-shadow:
        2px 2px 0px var(--f1-red),
        -1px -1px 0 var(--rb-navy);
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
    line-height: 1;
}

.subtitle {
    font-family: 'Outfit', sans-serif;
    color: var(--rb-yellow);
    text-transform: uppercase;
    letter-spacing: 4px;
    font-size: 0.8rem;
    font-weight: 900;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--f1-red);
    display: inline-block;
    padding-bottom: 5px;
}

/* Character Image */
.daphne-shrine {
    margin-bottom: 0.5rem;
    position: relative;
    height: 250px;
    /* Increased significantly */
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.5s ease;
}

/* State Management: Warning vs Daphne */
.daphne-shrine .character-container {
    display: none;
    /* Hidden by default */
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.daphne-shrine .warning-message {
    display: block;
    /* Visible by default */
    text-align: center;
    color: var(--f1-red);
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem 2rem;
    border: 1px dashed var(--f1-red);
    border-radius: 8px;
    animation: fadeIn 0.5s ease;
}

/* Reveal State: Swap visibility */
.daphne-shrine.reveal .character-container {
    display: flex;
}

.daphne-shrine.reveal .warning-message {
    display: none;
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Warning Styles */
.warning-message h2 {
    font-family: 'Racing Sans One', cursive;
    font-size: 1.8rem;
    letter-spacing: 2px;
    animation: blink 1s infinite alternate;
    margin-bottom: 5px;
}

.warning-message p {
    font-weight: 700;
    font-size: 1rem;
    color: var(--rb-yellow);
    letter-spacing: 1px;
}

.warning-message .arrow {
    font-size: 2.5rem;
    margin-top: 10px;
    color: white;
    animation: bounce 1.5s infinite;
}

@keyframes blink {
    from {
        text-shadow: 0 0 15px var(--f1-red);
        opacity: 1;
    }

    to {
        text-shadow: none;
        opacity: 0.5;
    }
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

/* Envelope Section */
.letter-section {
    perspective: 1000px;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Horizontally Center content */
    justify-content: center;
    /* Vertically Center content */
    height: 180px;
    margin-top: 0.5rem;
    /* Reduced margin */
    width: 100%;
    position: relative;
    /* Context for absolute items if any */
}

.envelope {
    /* Remove previous absolute positioning if any */
    position: relative;
    width: 240px;
    height: 160px;
    background: linear-gradient(135deg, #eee, #ccc);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 4px;
    transform-style: preserve-3d;
    /* Enhance 3D feel */
    margin: 0;
    /* Let flexbox handle centering */
}

.envelope:hover {
    transform: scale(1.05) rotate(2deg);
}

.envelope .flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
    border-left: 120px solid transparent;
    border-right: 120px solid transparent;
    border-top: 90px solid var(--f1-red);
    transform-origin: top;
    transition: transform 0.4s ease 0.6s, z-index 0.2s;
    /* Close: Flap comes down last */
    z-index: 5;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Wax Seal decoration */
.envelope .flap::after {
    content: 'TOP SECRET';
    position: absolute;
    top: -65px;
    left: -35px;
    background: var(--asphalt);
    color: var(--daphne-green);
    font-size: 8px;
    font-weight: 900;
    padding: 2px 4px;
    border: 1px solid var(--daphne-green);
    transform: rotate(-15deg);
    opacity: 0.8;
}

.envelope .body {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0;
    border-left: 120px solid transparent;
    border-right: 120px solid transparent;
    border-bottom: 90px solid #e0e0e0;
    z-index: 4;
    border-radius: 0 0 4px 4px;
}

/* The Letter */
.letter {
    position: absolute;
    top: 40px;
    /* Sit deeper in the pocket */
    left: 15px;
    width: 210px;
    /* Slightly narrower */
    height: 100px;
    /* Shorter when closed */
    background: #fffdf5;
    padding: 20px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.6s ease, height 0.6s ease, top 0.6s ease, z-index 0.1s;
    z-index: 2;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.letter .text {
    opacity: 0;
    transition: opacity 0.1s ease;
    /* Disappear immediately on close */
    color: var(--daphne-purple);
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1.4;
}

.heart {
    display: block;
    margin-top: 10px;
    font-size: 1.8rem;
    animation: heartbeat 1.5s infinite;
}

@keyframes heartbeat {
    0% {
        transform: scale(1);
    }

    15% {
        transform: scale(1.3);
    }

    30% {
        transform: scale(1);
    }

    45% {
        transform: scale(1.15);
    }

    60% {
        transform: scale(1);
    }
}

/* Open State */
.envelope.open {
    cursor: default;
    transform: translateY(20px);
}

.envelope.open .flap {
    transform: rotateX(180deg);
    z-index: 1;
    border-top-color: #cc1300;
    transition: transform 0.4s ease, z-index 0.2s;
    /* Open: Flap goes up first */
}

.envelope.open .letter {
    transform: translateY(-120px);
    z-index: 6;
    height: 250px;
    top: 10px;
    /* Reset top position when expanded */
    transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.4s, height 0.6s ease 0.4s, top 0.6s ease 0.4s, z-index 0s linear 0.4s;
}

.envelope.open .letter .text {
    opacity: 1;
    transition: opacity 1s ease 1.2s;
    /* Delay fade in on open */
}

.instruction {
    margin-top: 1.5rem;
    font-size: 0.75rem;
    opacity: 0.8;
    color: var(--daphne-green);
    letter-spacing: 2px;
    text-transform: uppercase;
    animation: pulse 2s infinite;
}

/* Responsive */
@media (max-width: 480px) {
    .container {
        width: 85%;
        /* Reduced width to show more background cars */
        padding: 1rem 0.5rem;
        /* Tighter padding */
    }

    .hero h1 {
        font-size: 2rem;
        /* Smaller title */
        letter-spacing: 0;
    }

    .rb-logo {
        width: 150px;
        /* Smaller logo */
    }

    .daphne-shrine {
        height: 140px;
        /* Reduced height for mobile */
    }

    .daphne-full {
        max-height: 120px;
        /* Smaller image */
    }

    .envelope {
        width: 200px;
        height: 140px;
    }

    .envelope .flap {
        border-left: 100px solid transparent;
        border-right: 100px solid transparent;
        border-top: 80px solid var(--f1-red);
    }

    .envelope .body {
        border-left: 100px solid transparent;
        border-right: 100px solid transparent;
        border-bottom: 80px solid #e0e0e0;
    }

    .letter {
        width: 180px;
        height: 90px;
        left: 10px;
    }

    .letter-section {
        height: 160px;
    }
}