/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Default palette (will be overridden by JS) */
    --primary: #9b59b6;
    --accent: #e8b4f0;
    --background: #1a0d1f;
    --glow: #d4a5e8;
    --text: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.8);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text);
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
    width: 100vw;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   SCREEN MANAGEMENT
   ============================================ */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease, visibility 0.6s ease;
    will-change: opacity;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   PERSONALIZATION SCREEN
   ============================================ */
#personalization-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a0d1f 0%, #2d1b3d 100%);
    padding: 2rem;
    min-height: 100vh;
}

.container {
    max-width: 500px;
    width: 100%;
    text-align: center;
    padding: 1rem 0;
}

.intro-title {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    font-weight: 400;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    color: var(--text);
    animation: gentlePulse 3s ease-in-out infinite;
}

.subtitle {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    font-weight: 300;
    letter-spacing: 0.3px;
    margin-bottom: 3rem;
    color: var(--text-secondary);
}

@keyframes gentlePulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

.input-group {
    margin-bottom: 2.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.input-group input {
    width: 100%;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s ease;
    outline: none;
}

.input-group input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--glow);
    box-shadow: 0 0 20px rgba(212, 165, 232, 0.2);
    transform: scale(1.02);
}

.input-group input.error {
    border-color: #ff6b6b;
    box-shadow: 0 0 15px rgba(255, 107, 107, 0.3);
}

.error-message {
    display: none;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #ff6b6b;
    font-weight: 400;
    animation: gentleShake 0.3s ease;
}

.error-message.show {
    display: block;
}

@keyframes gentleShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.palette-group {
    margin-bottom: 2.5rem;
    position: relative;
}

.palette-group label {
    display: block;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 400;
    text-align: left;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.palette-option {
    position: relative;
    padding: 1.25rem;
    border-radius: 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.palette-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--pal-primary), var(--pal-accent));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.palette-option:hover {
    transform: scale(1.05);
    border-color: var(--pal-glow);
    box-shadow: 0 0 30px rgba(212, 165, 232, 0.3);
}

.palette-option:hover::before {
    opacity: 0.15;
}

.palette-option.selected {
    border-color: var(--pal-glow);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 40px var(--pal-glow);
    transform: scale(1.08);
}

.palette-option.selected::before {
    opacity: 0.25;
}

.palette-name {
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.palette-swatches {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.palette-swatch {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.continue-btn {
    width: 100%;
    padding: 1.25rem 2rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    border-radius: 12px;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(155, 89, 182, 0.3);
}

.continue-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.continue-btn:not(:disabled):active::before {
    width: 300px;
    height: 300px;
}

.continue-btn:not(:disabled):hover {
    transform: scale(1.02);
    box-shadow: 0 6px 30px rgba(155, 89, 182, 0.4);
}

.continue-btn:not(:disabled):active {
    transform: scale(0.98);
}

.continue-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.continue-btn:not(:disabled) {
    animation: softGlow 2s ease-in-out infinite;
}

@keyframes softGlow {
    0%, 100% { box-shadow: 0 4px 20px rgba(155, 89, 182, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(155, 89, 182, 0.5); }
}

/* ============================================
   VALENTINE EXPERIENCE SCREEN
   ============================================ */
#valentine-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--background) 0%, var(--primary) 100%);
    padding: 2rem;
    min-height: 100vh;
}

.valentine-container {
    max-width: 600px;
    width: 100%;
    text-align: center;
    position: relative;
    z-index: 1;
}

.typing-container {
    min-height: 200px;
    margin-bottom: 2rem;
    text-align: left;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    backdrop-filter: blur(10px);
}

.typing-text {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    line-height: 1.8;
    color: var(--text);
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
}

.cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--glow);
    margin-left: 2px;
    animation: blink 1s infinite;
    vertical-align: middle;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.countdown {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 300;
    margin-bottom: 3rem;
    color: var(--glow);
    text-shadow: 0 0 20px var(--glow);
    animation: gentlePulse 2s ease-in-out infinite;
}

.button-group {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 2rem;
}

.accept-btn,
.decline-btn {
    padding: 1.25rem 2.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    min-width: 160px;
}

.accept-btn {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--text);
    box-shadow: 0 4px 20px rgba(155, 89, 182, 0.4);
}

.accept-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(155, 89, 182, 0.6);
}

.accept-btn:active {
    transform: scale(1.02);
}

.accept-btn {
    animation: softGlow 2s ease-in-out infinite;
}

.decline-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.decline-btn:hover {
    transform: translateX(10px);
    background: rgba(255, 255, 255, 0.15);
}

.decline-btn:active {
    transform: translateX(15px) scale(0.98);
}

/* Canvas for floating hearts and emojis */
#heartsCanvas,
#emojisCanvas,
#finalEmojisCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

#emojisCanvas,
#finalEmojisCanvas {
    z-index: 1;
}

/* ============================================
   FINAL SCREEN
   ============================================ */
#final-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--background) 0%, var(--primary) 100%);
    padding: 2rem;
    min-height: 100vh;
}

.final-container {
    max-width: 600px;
    width: 100%;
    text-align: center;
    position: relative;
    z-index: 1;
}

.final-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 300;
    margin-bottom: 2rem;
    color: var(--glow);
    text-shadow: 0 0 30px var(--glow);
    animation: gentlePulse 2s ease-in-out infinite;
}

.final-name {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 400;
    margin-bottom: 1rem;
    color: var(--text);
}

.final-message {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    font-weight: 300;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.final-greeting {
    font-size: clamp(1rem, 2.5vw, 1.3rem);
    font-weight: 300;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.save-btn {
    padding: 1.25rem 2.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.save-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.1);
}

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

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    #personalization-screen,
    #valentine-screen,
    #final-screen {
        padding: 1.5rem 1rem;
    }
    
    .container,
    .valentine-container,
    .final-container {
        padding: 0.5rem 0;
    }
    
    .palette-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .button-group {
        flex-direction: column;
        align-items: center;
    }
    
    .accept-btn,
    .decline-btn {
        width: 100%;
        max-width: 280px;
    }
}

@media (max-width: 480px) {
    #personalization-screen,
    #valentine-screen,
    #final-screen {
        padding: 1rem 0.75rem;
    }
    
    .container,
    .valentine-container,
    .final-container {
        padding: 0.5rem 0;
    }
    
    .typing-container {
        padding: 1rem;
    }
    
    .intro-title {
        margin-bottom: 1.5rem;
    }
    
    .subtitle {
        margin-bottom: 2rem;
    }
    
    .input-group {
        margin-bottom: 1.5rem;
    }
    
    .palette-group {
        margin-bottom: 1.5rem;
    }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */
.screen,
.palette-option,
.continue-btn,
.accept-btn,
.decline-btn,
.save-btn {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
