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

body {
    font-family: 'Quicksand', sans-serif;
    background: linear-gradient(135deg, #1a0033 0%, #2d1b4e 25%, #4B0082 50%, #7b4fa3 75%, #c4b5d6 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    touch-action: pan-y pinch-zoom;
}

.stars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* GPU layer for smoother rendering */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    contain: strict;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    animation: twinkle 4s ease-in-out infinite;
    /* GPU acceleration to prevent flickering */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: opacity;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

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

.container {
    text-align: center;
    padding: 20px;
    max-width: 500px;
    width: 100%;
    position: relative;
    z-index: 1;
    transform: translateY(-60px);
}

h1 {
    font-family: 'Cormorant Garamond', serif;
    color: #E6E6FA;
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(230, 230, 250, 0.4);
    font-weight: 300;
}

.instruction {
    color: rgba(230, 230, 250, 0.8);
    margin-bottom: 40px;
}

/* CAKE SECTION */
.cake-container {
    position: relative;
    display: inline-block;
    cursor: pointer;
    transition: transform 0.3s;
    -webkit-tap-highlight-color: transparent;
}
.cake-container:active { transform: scale(0.95); }

/* Shake animation for drum roll */
.cake-container.shaking {
    animation: cakeShake 0.1s ease-in-out infinite;
}

@keyframes cakeShake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-3px) rotate(-1deg); }
    75% { transform: translateX(3px) rotate(1deg); }
}

.tap-count {
    position: absolute;
    bottom: -48px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.12);
    color: white;
    padding: 6px 10px;
    border-radius: 20px;
    font-weight: 600;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.25);
    transition: transform 0.15s ease;
    pointer-events: none;
}

.cake-image {
    width: 200px;
    height: 200px;
    object-fit: contain;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
}

/* SWIPE STACK SECTION */
.surprise-container {
    display: none;
    width: 100%;
    position: relative;
    opacity: 0;
    transform: translateY(50px);
}
.surprise-container.show {
    display: block;
    animation: slideUpFadeIn 1s ease-out forwards;
}

@keyframes slideUpFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stack-area {
    position: relative;
    height: 450px;
    width: 100%;
    margin-top: 20px;
    perspective: 1200px;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    /* Prevent iOS scroll bounce during drag */
    overscroll-behavior: contain;
}

/* Glass morphism card with purple gradient */
.card {
    position: absolute;
    width: calc(100% - 20px);
    left: 10px;
    height: 100%;
    /* Glass morphism base */
    background: linear-gradient(
        135deg,
        rgba(147, 51, 234, 0.3) 0%,
        rgba(126, 34, 206, 0.4) 30%,
        rgba(168, 85, 247, 0.35) 50%,
        rgba(139, 92, 246, 0.4) 70%,
        rgba(192, 132, 252, 0.3) 100%
    );
    /* Blur effect - reduced for better performance */
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    /* Glass border effect */
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    border-left: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    padding: 16px;
    /* Simplified shadow for better performance */
    box-shadow: 
        0 8px 32px rgba(31, 38, 135, 0.37),
        0 4px 16px rgba(147, 51, 234, 0.2);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    flex-direction: column;
    transform-origin: center bottom;
    touch-action: none;
    /* Critical: GPU layer promotion for Chrome mobile */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    /* Prevent flickering with perspective */
    -webkit-perspective: 1000;
    perspective: 1000;
    /* Optimize paint containment */
    contain: layout style paint;
    /* Stacking offset applied via JS */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), 
                box-shadow 0.3s ease;
}

/* Stack offset classes - crossed/fanned card effect */
.card[data-stack="0"] {
    transform: translateY(0) scale(1) rotate(0deg);
    z-index: 10;
}
.card[data-stack="1"] {
    transform: translateX(12px) translateY(6px) scale(0.97) rotate(6deg);
    z-index: 9;
    filter: brightness(0.95);
}
.card[data-stack="2"] {
    transform: translateX(-14px) translateY(12px) scale(0.94) rotate(-7deg);
    z-index: 8;
    filter: brightness(0.9);
}
.card[data-stack="3"] {
    transform: translateX(10px) translateY(18px) scale(0.91) rotate(5deg);
    z-index: 7;
    filter: brightness(0.85);
}
.card[data-stack="4"] {
    transform: translateX(-12px) translateY(24px) scale(0.88) rotate(-6deg);
    z-index: 6;
    filter: brightness(0.8);
}
.card[data-stack="5"] {
    transform: translateX(8px) translateY(30px) scale(0.85) rotate(4deg);
    z-index: 5;
    filter: brightness(0.75);
}
.card[data-stack="6"],
.card[data-stack="7"],
.card[data-stack="8"],
.card[data-stack="9"] {
    transform: translateX(-6px) translateY(36px) scale(0.82) rotate(-3deg);
    z-index: 4;
    filter: brightness(0.7);
}

/* Pop-in animation for cards */
.card.pop-in {
    animation: cardPopIn 0.25s ease-out forwards;
}

@keyframes cardPopIn {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    100% {
        opacity: 1;
    }
}

/* Shimmer overlay effect */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 100%
    );
    border-radius: 24px;
    animation: shimmer 4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes shimmer {
    0%, 100% { left: -100%; }
    50% { left: 100%; }
}

/* Active dragging state */
.card:active { cursor: grabbing; }

.card.dragging {
    box-shadow: 
        0 25px 50px rgba(31, 38, 135, 0.5),
        0 15px 35px rgba(147, 51, 234, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    filter: brightness(1.05);
    z-index: 100 !important;
    /* Disable transitions during drag for instant response */
    transition: box-shadow 0.15s ease, filter 0.15s ease;
    /* Force GPU layer */
    will-change: transform, opacity;
    /* Disable pointer events on children during drag */
    pointer-events: auto;
}

/* Swipe direction indicators */
.card.swiping-left {
    background: linear-gradient(
        135deg,
        rgba(239, 68, 68, 0.2) 0%,
        rgba(147, 51, 234, 0.3) 50%,
        rgba(168, 85, 247, 0.3) 100%
    );
}

.card.swiping-right {
    background: linear-gradient(
        135deg,
        rgba(168, 85, 247, 0.3) 0%,
        rgba(147, 51, 234, 0.3) 50%,
        rgba(34, 197, 94, 0.2) 100%
    );
}

/* Card image styling */
.card-img {
    width: 100%;
    height: 280px;
    object-fit: cover;
    border-radius: 16px;
    margin-bottom: 12px;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Card message styling */
.card-msg {
    color: white;
    font-size: 1.05rem;
    font-weight: 400;
    line-height: 1.5;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    /* Simplified background - no blur for better performance */
    background: rgba(255, 255, 255, 0.12);
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .stack-area {
        height: 420px;
        perspective: 1000px;
        /* Prevent flickering on scroll */
        -webkit-overflow-scrolling: touch;
    }
    
    .card {
        width: calc(100% - 16px);
        left: 8px;
        padding: 14px;
        border-radius: 20px;
        /* Reduced blur for mobile - lower value = better performance */
        backdrop-filter: blur(8px) saturate(140%);
        -webkit-backdrop-filter: blur(8px) saturate(140%);
        /* Semi-opaque background with blur */
        background: linear-gradient(
            135deg,
            rgba(147, 51, 234, 0.45) 0%,
            rgba(126, 34, 206, 0.5) 30%,
            rgba(168, 85, 247, 0.45) 50%,
            rgba(139, 92, 246, 0.5) 70%,
            rgba(192, 132, 252, 0.45) 100%
        );
        /* Force GPU layer on mobile Chrome */
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
    
    .card::before {
        /* Disable shimmer on mobile for performance */
        animation: none !important;
        display: none !important;
    }
    
    .card-img {
        height: 260px;
        border-radius: 14px;
    }
    
    .card-msg {
        font-size: 1rem;
        padding: 10px 12px;
        /* Disable blur for performance */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(255, 255, 255, 0.15);
    }
    
    /* Stack offsets for mobile - crossed effect */
    .card[data-stack="1"] {
        transform: translateX(8px) translateY(5px) scale(0.97) rotate(5deg);
    }
    .card[data-stack="2"] {
        transform: translateX(-10px) translateY(10px) scale(0.94) rotate(-6deg);
    }
    .card[data-stack="3"] {
        transform: translateX(7px) translateY(15px) scale(0.91) rotate(4deg);
    }
    .card[data-stack="4"],
    .card[data-stack="5"],
    .card[data-stack="6"],
    .card[data-stack="7"],
    .card[data-stack="8"],
    .card[data-stack="9"] {
        transform: translateX(-5px) translateY(20px) scale(0.88) rotate(-3deg);
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .stack-area {
        height: 380px;
    }
    
    .card-img {
        height: 220px;
    }
    
    .card-msg {
        font-size: 0.95rem;
    }
}

.swipe-hint {
    color: rgba(255,255,255,0.6);
    margin-top: 55px;
    font-size: 0.9rem;
    background: rgba(255,255,255,0.08);
    padding: 10px 20px;
    border-radius: 20px;
    display: inline-block;
    border: 1px solid rgba(255,255,255,0.1);
    /* GPU layer */
    transform: translateZ(0);
}

/* Desktop optimizations - larger cards */
@media (min-width: 769px) {
    .container {
        max-width: 600px;
    }
    
    .stack-area {
        height: 550px;
        perspective: 1400px;
    }
    
    .card {
        padding: 20px;
        border-radius: 28px;
    }
    
    .card-img {
        height: 380px;
        border-radius: 20px;
    }
    
    .card-msg {
        font-size: 1.15rem;
        padding: 14px 20px;
    }
}

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

.sparkle {
    position: absolute;
    pointer-events: none;
    animation: burst 0.8s ease-out forwards;
}
@keyframes burst {
    0% { transform: scale(0); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

#intro {
    transition: all 0.8s ease-out;
}

#intro.fade-out {
    opacity: 0;
    transform: scale(1.5) rotate(360deg);
    filter: blur(20px);
}
