/* ============================================
   Premium Valentine Website - Stylesheet
   ============================================
   
   @version 2.0.0
   @author Valentine Experience Team
   @license MIT
   
   Architecture:
   - CSS Custom Properties for maintainable design system
   - Hardware-accelerated animations (transform/opacity only)
   - Mobile-first responsive design with fluid typography
   - WCAG 2.1 AA compliant (color contrast, focus states)
   - Cross-browser compatibility with vendor prefixes
   - Reduced motion support for accessibility
   - Print-optimized styles
   
   Performance:
   - GPU-accelerated transforms with translate3d
   - will-change hints for animation optimization
   - Minimal repaints/reflows
   - 60fps target on mobile devices
   ============================================ */

/* ===========================================
   CSS Custom Properties (Design Tokens)
   Corporate-Grade Design System
   =========================================== */
:root {
    /* Primary Colors - Premium Palette */
    --color-crimson: #8b0000;
    --color-crimson-dark: #6d0000;
    --color-crimson-light: #a01010;
    --color-blush: #ffb6c1;
    --color-blush-light: #ffd1d9;
    --color-champagne: #f9f9f9;
    --color-white: #ffffff;

    /* Accent Colors */
    --color-gold: #d4af37;
    --color-rose: #ff6b81;
    --color-pink-soft: #ffe4e9;

    /* Text Colors - WCAG 2.1 AA Compliant */
    --text-primary: #2d2d2d;        /* Contrast ratio: 12.63:1 */
    --text-secondary: #666666;      /* Contrast ratio: 5.74:1 */
    --text-light: #ffffff;

    /* Shadows - Layered Depth System */
    --shadow-soft: 0 4px 20px rgba(139, 0, 0, 0.1);
    --shadow-medium: 0 8px 32px rgba(139, 0, 0, 0.15);
    --shadow-heavy: 0 12px 48px rgba(139, 0, 0, 0.2);
    --shadow-glow: 0 0 40px rgba(255, 182, 193, 0.4);
    --shadow-focus: 0 0 0 3px rgba(139, 0, 0, 0.3);

    /* Glass Effect - Premium Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-bg-fallback: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-blur: 20px;

    /* Typography - Fluid Scaling System */
    --font-heading: 'Playfair Display', Georgia, serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Fluid Typography */
    --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --font-size-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --font-size-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --font-size-lg: clamp(1.125rem, 1rem + 0.625vw, 1.5rem);
    --font-size-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2.5rem);
    --font-size-2xl: clamp(2rem, 1.5rem + 2.5vw, 4rem);

    /* Spacing - 8pt Grid System */
    --space-xs: 0.5rem;     /* 8px */
    --space-sm: 1rem;       /* 16px */
    --space-md: 1.5rem;     /* 24px */
    --space-lg: 2rem;       /* 32px */
    --space-xl: 3rem;       /* 48px */
    --space-2xl: 4rem;      /* 64px */

    /* Transitions - Premium Easing Functions */
    --ease-premium: cubic-bezier(0.4, 0, 0.2, 1);           /* Material Design Standard */
    --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);  /* Playful Bounce */
    --ease-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);    /* Smooth Ease Out */
    --ease-elastic: cubic-bezier(0.68, -0.6, 0.32, 1.6);    /* Elastic Effect */
    
    /* Transition Durations */
    --duration-instant: 100ms;
    --duration-fast: 200ms;
    --duration-normal: 300ms;
    --duration-slow: 500ms;
    --duration-slower: 800ms;

    /* Z-Index Scale - Strict Layering System */
    --z-base: 1;
    --z-notes: 10;
    --z-notes-dragging: 20;
    --z-envelope: 50;
    --z-question: 30;
    --z-success: 60;
    --z-overlay: 100;
    --z-button-evading: 200;
    --z-modal: 1000;
    --z-confetti: 9999;
    
    /* Border Radius - Consistent Rounding */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 24px;
    --radius-full: 50px;
    
    /* Performance Hints */
    --gpu-hack: translateZ(0);
}

/* ===========================================
   Reset & Base Styles
   =========================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--color-champagne) 0%, var(--color-blush-light) 50%, var(--color-pink-soft) 100%);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent text selection during drag */
.dragging {
    user-select: none;
    -webkit-user-select: none;
    cursor: grabbing !important;
}

/* Focus visible for keyboard navigation (WCAG 2.1 AA) */
*:focus-visible {
    outline: 3px solid var(--color-crimson);
    outline-offset: 2px;
    box-shadow: var(--shadow-focus);
    transition: outline-offset var(--duration-fast) var(--ease-premium);
}

/* Remove default focus for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    *:focus-visible {
        outline-width: 4px;
        outline-offset: 3px;
    }
}

/* ===========================================
   Noise Texture Overlay
   =========================================== */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: var(--z-overlay);
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* ===========================================
   Confetti Canvas
   =========================================== */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: var(--z-confetti);
}

/* ===========================================
   Main Container
   =========================================== */
.container {
    position: relative;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

/* ===========================================
   Glassmorphism Container
   Premium Glass Effect with Fallbacks
   =========================================== */
.glass-container {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-medium);
}

/* Fallback for browsers without backdrop-filter support */
@supports not (backdrop-filter: blur(20px)) {
    .glass-container {
        background: var(--glass-bg-fallback);
        box-shadow: var(--shadow-heavy);
    }
}

/* Safari-specific optimization */
@supports (-webkit-backdrop-filter: blur(20px)) {
    .glass-container {
        -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    }
}

/* ===========================================
   Section Base Styles
   =========================================== */
section {
    position: absolute;
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: opacity 0.6s var(--ease-premium), transform 0.6s var(--ease-premium);
}

section.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95);
}

/* ===========================================
   STAGE 1: Envelope Section
   =========================================== */
.envelope-section {
    z-index: var(--z-envelope);
}

.envelope-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
}

.envelope {
    position: relative;
    width: 280px;
    height: 200px;
    perspective: 1000px;
    cursor: pointer;
    /* Hardware acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.envelope-body {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, var(--color-blush) 0%, var(--color-blush-light) 100%);
    border-radius: 8px;
    box-shadow: var(--shadow-medium);
    overflow: hidden;
}

.envelope-body::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60%;
    background: linear-gradient(145deg, #f8c8d0 0%, var(--color-blush) 100%);
    clip-path: polygon(0 40%, 50% 0, 100% 40%, 100% 100%, 0 100%);
}

.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: linear-gradient(180deg, var(--color-blush-light) 0%, var(--color-blush) 100%);
    clip-path: polygon(0 0, 50% 100%, 100% 0);
    transform-origin: top center;
    transition: transform 0.8s var(--ease-premium);
    z-index: 2;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    /* Hardware acceleration */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.envelope.open .envelope-flap {
    transform: rotateX(180deg);
}

.letter {
    position: absolute;
    top: 20%;
    left: 10%;
    width: 80%;
    height: 70%;
    background: var(--color-white);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate3d(0, 0, 0);
    transition: transform 0.8s var(--ease-bounce) 0.3s;
    z-index: 1;
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.envelope.open .letter {
    transform: translate3d(0, -60%, 0);
}

.letter-content {
    text-align: center;
    padding: var(--space-sm);
}

.letter-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: var(--space-xs);
    animation: pulse 2s ease-in-out infinite;
}

.letter-text {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Open Button */
.btn-open {
    position: relative;
    padding: 16px 48px;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-light);
    background: linear-gradient(135deg, var(--color-crimson) 0%, var(--color-crimson-light) 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.3s var(--ease-bounce), box-shadow 0.3s var(--ease-premium);
    box-shadow: 0 4px 20px rgba(139, 0, 0, 0.3);
    min-height: 48px;
    min-width: 160px;
    will-change: transform;
    animation: pulse-shadow 2s ease-in-out infinite;
    /* Hardware acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.btn-open:hover {
    transform: translate3d(0, -2px, 0) scale(1.02);
    box-shadow: 0 8px 30px rgba(139, 0, 0, 0.4);
}

.btn-open:active {
    transform: translate3d(0, 0, 0) scale(0.98);
}

.btn-open:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-open::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn-open:hover::before {
    left: 100%;
}

/* Pulse Shadow Animation */
@keyframes pulse-shadow {

    0%,
    100% {
        box-shadow: 0 4px 20px rgba(139, 0, 0, 0.3), 0 0 0 0 rgba(139, 0, 0, 0.4);
    }

    50% {
        box-shadow: 0 4px 20px rgba(139, 0, 0, 0.3), 0 0 0 15px rgba(139, 0, 0, 0);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* ===========================================
   STAGE 2: Notes Section
   =========================================== */
.notes-section {
    z-index: var(--z-notes);
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    padding: var(--space-md);
}

.notes-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 600px;
    max-height: 600px;
}

.draggable-note {
    position: absolute;
    width: 160px;
    height: 160px;
    cursor: grab;
    transition: box-shadow 0.3s var(--ease-premium);
    will-change: transform;
    touch-action: none;
    /* Hardware acceleration for 60fps */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.draggable-note:active {
    cursor: grabbing;
}

.draggable-note.dragging {
    transition: box-shadow var(--duration-normal) var(--ease-premium);
    box-shadow: var(--shadow-heavy), 0 0 30px rgba(139, 0, 0, 0.2);
    z-index: var(--z-notes-dragging) !important;
}

.note-inner {
    width: 100%;
    height: 100%;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 12px;
    box-shadow: var(--shadow-medium);
}

.note-emoji {
    font-size: 2.5rem;
    margin-bottom: var(--space-sm);
}

.note-inner p {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    color: var(--text-primary);
    font-style: italic;
    line-height: 1.4;
}

/* Note Variations */
.note-1 {
    top: 15%;
    left: 20%;
    transform: rotate(-5deg);
    z-index: 15;
}

.note-1 .note-inner {
    background: linear-gradient(145deg, #fff5f5 0%, #ffe4e9 100%);
}

.note-2 {
    top: 25%;
    right: 15%;
    transform: rotate(8deg);
    z-index: 14;
}

.note-2 .note-inner {
    background: linear-gradient(145deg, #fff8f0 0%, #ffecd9 100%);
}

.note-3 {
    top: 45%;
    left: 10%;
    transform: rotate(3deg);
    z-index: 13;
}

.note-3 .note-inner {
    background: linear-gradient(145deg, #f5fff5 0%, #e4f5e4 100%);
}

.note-4 {
    top: 50%;
    right: 20%;
    transform: rotate(-7deg);
    z-index: 12;
}

.note-4 .note-inner {
    background: linear-gradient(145deg, #f5f5ff 0%, #e4e4f5 100%);
}

.note-5 {
    top: 35%;
    left: 35%;
    transform: rotate(2deg);
    z-index: 16;
}

.note-5 .note-inner {
    background: linear-gradient(145deg, var(--color-blush-light) 0%, var(--color-blush) 100%);
}

.hint-text {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-secondary);
    opacity: 0.8;
    animation: fadeInUp 0.6s var(--ease-premium) forwards;
    text-align: center;
    width: 100%;
    padding: 0 var(--space-md);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 0.8;
        transform: translateX(-50%) translateY(0);
    }
}

/* ===========================================
   STAGE 3: Question Section
   =========================================== */
.question-section {
    z-index: var(--z-question);
}

.question-container {
    padding: var(--space-xl) var(--space-lg);
    max-width: 420px;
    width: 100%;
}

.question-title {
    font-family: var(--font-heading);
    font-size: clamp(1.8rem, 6vw, 2.5rem);
    font-weight: 600;
    color: var(--color-crimson);
    margin-bottom: var(--space-sm);
    line-height: 1.2;
}

.question-subtitle {
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xl);
}

.buttons-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 80px;
}

/* Button Base */
.btn {
    position: relative;
    padding: 16px 40px;
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s var(--ease-bounce);
    min-height: 48px;
    min-width: 120px;
    will-change: transform;
    /* Hardware acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Yes Button */
.btn-yes {
    color: var(--text-light);
    background: linear-gradient(135deg, var(--color-crimson) 0%, var(--color-rose) 100%);
    box-shadow: 0 4px 20px rgba(139, 0, 0, 0.3);
    transform-origin: center;
}

.btn-yes:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(139, 0, 0, 0.4);
}

.btn-yes:active {
    transform: scale(0.98);
}

/* No Button */
.btn-no {
    color: var(--text-secondary);
    background: var(--color-champagne);
    border: 2px solid #ddd;
    box-shadow: var(--shadow-soft);
    transition: background 0.2s var(--ease-premium);
    position: relative;
}

.btn-no:hover {
    background: #f0f0f0;
}

.btn-no.evading {
    position: fixed !important;
    transition: left var(--duration-normal) var(--ease-smooth), 
                top var(--duration-normal) var(--ease-smooth), 
                transform var(--duration-normal) var(--ease-smooth);
    z-index: var(--z-button-evading);
}

/* ===========================================
   STAGE 4: Success Section
   =========================================== */
.success-section {
    z-index: var(--z-success);
}

.success-container {
    padding: var(--space-xl) var(--space-lg);
    max-width: 420px;
    width: 100%;
    animation: successPop 0.6s var(--ease-bounce) forwards;
}

@keyframes successPop {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.success-hearts {
    font-size: 4rem;
    margin-bottom: var(--space-md);
    animation: heartBeat 1s ease-in-out infinite;
}

@keyframes heartBeat {

    0%,
    100% {
        transform: scale(1);
    }

    25% {
        transform: scale(1.1);
    }

    50% {
        transform: scale(1);
    }

    75% {
        transform: scale(1.15);
    }
}

.success-title {
    font-family: var(--font-heading);
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 700;
    color: var(--color-crimson);
    margin-bottom: var(--space-sm);
}

.success-subtitle {
    font-family: var(--font-body);
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.success-message {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* ===========================================
   Custom Scrollbar
   =========================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-champagne);
}

::-webkit-scrollbar-thumb {
    background: var(--color-blush);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-crimson);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-blush) var(--color-champagne);
}

/* ===========================================
   Mobile Responsive Styles
   =========================================== */
@media screen and (max-width: 768px) {
    :root {
        --space-lg: 1.5rem;
        --space-xl: 2rem;
    }

    .envelope {
        width: 240px;
        height: 170px;
    }

    .draggable-note {
        width: 130px;
        height: 130px;
    }

    .note-emoji {
        font-size: 2rem;
    }

    .note-inner p {
        font-size: 0.85rem;
    }

    /* Reposition notes for mobile */
    .note-1 {
        top: 5%;
        left: 5%;
    }

    .note-2 {
        top: 10%;
        right: 5%;
    }

    .note-3 {
        top: 40%;
        left: 5%;
    }

    .note-4 {
        top: 45%;
        right: 5%;
    }

    .note-5 {
        top: 25%;
        left: 25%;
    }

    .question-container,
    .success-container {
        padding: var(--space-lg);
        margin: 0 var(--space-sm);
    }

    .buttons-wrapper {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .btn {
        width: 100%;
        max-width: 200px;
    }
}

@media screen and (max-width: 380px) {
    .envelope {
        width: 200px;
        height: 140px;
    }

    .btn-open {
        padding: 14px 36px;
        font-size: 0.9rem;
    }

    .draggable-note {
        width: 110px;
        height: 110px;
    }

    .note-inner {
        padding: var(--space-sm);
    }

    .note-emoji {
        font-size: 1.5rem;
        margin-bottom: var(--space-xs);
    }

    .note-inner p {
        font-size: 0.75rem;
    }
}

/* ===========================================
   Accessibility: Reduced Motion Preferences
   WCAG 2.1 Level AA Compliance
   =========================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* Maintain functionality while respecting motion preferences */
    .envelope.open .envelope-flap {
        transform: rotateX(180deg);
        transition: none;
    }
    
    .envelope.open .letter {
        transform: translate3d(0, -60%, 0);
        transition: none;
    }
}

/* ===========================================
   Accessibility: High Contrast Mode
   =========================================== */
@media (prefers-contrast: high) {
    :root {
        --color-crimson: #990000;
        --text-primary: #000000;
        --text-secondary: #333333;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
    
    .glass-container {
        background: rgba(255, 255, 255, 0.98);
        border: 2px solid var(--color-crimson);
    }
}

/* ===========================================
   Dark Mode Support (Future Enhancement)
   =========================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --color-champagne: #1a1a1a;
        --text-primary: #e0e0e0;
        --text-secondary: #a0a0a0;
        --glass-bg: rgba(30, 30, 30, 0.7);
        --glass-bg-fallback: rgba(30, 30, 30, 0.95);
    }
    
    body {
        background: linear-gradient(135deg, #1a1a1a 0%, #2d1a1a 50%, #3d1a1a 100%);
    }
}

/* ===========================================
   Print Styles
   =========================================== */
@media print {

    .noise-overlay,
    #confetti-canvas,
    .btn {
        display: none;
    }

    body {
        background: white;
    }
}