/* =============================================
   GLÜCKSKEKS V3 - Professional Fortune Cookie
   
   Features:
   - Paper-style mesh gradient (pink/warm tones)
   - Mood badge for humor days
   - Test panel for date simulation
   - Improved text positioning on frames
   - Frame-matched text colors
   ============================================= */

/* ===== CSS VARIABLES ===== */
:root {
    /* Colors - Pink/Warm theme matching frames */
    --color-bg-dark: #0a0808;
    --color-pink-dark: #2a1520;
    --color-pink-medium: #4a2040;
    --color-pink-light: #8a4070;
    --color-cream: #f5e6d3;
    
    --color-text-light: rgba(255, 255, 255, 0.9);
    --color-text-muted: rgba(255, 255, 255, 0.5);
    --color-text-subtle: rgba(255, 255, 255, 0.3);
    
    /* Frame-specific text colors */
    --color-flamingo: #c43a67;
    --color-blue: #3d5a80;
    --color-dragon: #8b3a3a;
    
    /* Typography */
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Playfair Display', Georgia, serif;
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2.5rem;
    --spacing-xl: 4rem;
    
    /* Transitions */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-in-out-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Sizes */
    --cookie-size: min(80vw, 380px);
    --fortune-width: min(92vw, 480px);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    color: var(--color-text-light);
    background: var(--color-bg-dark);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    position: relative;
    touch-action: manipulation;
}

/* ===== ANIMATED MESH GRADIENT ===== */
#gradient-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ===== NOISE OVERLAY ===== */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
}

/* ===== AMBIENT GLOW ===== */
.ambient-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
    animation: float 25s ease-in-out infinite;
}

.glow-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(196, 58, 103, 0.25) 0%, transparent 70%);
    top: -15%;
    left: -10%;
    animation-delay: 0s;
}

.glow-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(61, 90, 128, 0.2) 0%, transparent 70%);
    bottom: 5%;
    right: -5%;
    animation-delay: -8s;
}

.glow-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(139, 58, 58, 0.2) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translateX(-50%);
    animation-delay: -16s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(40px, -40px) scale(1.08); }
    50% { transform: translate(-30px, 30px) scale(0.95); }
    75% { transform: translate(30px, 40px) scale(1.03); }
}

/* ===== MOOD BADGE ===== */
.mood-badge {
    position: fixed;
    top: calc(var(--spacing-lg) + env(safe-area-inset-top, 0));
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(196, 58, 103, 0.15);
    border: 1px solid rgba(196, 58, 103, 0.3);
    border-radius: 100px;
    backdrop-filter: blur(10px);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s var(--ease-out-expo);
}

.mood-badge.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.mood-icon {
    font-size: 1.1rem;
}

.mood-text {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-flamingo);
}

/* ===== MAIN CONTAINER ===== */
.container {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-xl) + env(safe-area-inset-bottom, 0));
}

/* ===== COOKIE STAGE ===== */
.cookie-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.cookie-container {
    position: relative;
    width: var(--cookie-size);
    height: calc(var(--cookie-size) * 0.73);
    cursor: pointer;
    transition: transform 0.3s var(--ease-out-back);
}

.cookie-container:hover {
    transform: scale(1.02);
}

.cookie-container:active {
    transform: scale(0.98);
}

.cookie {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.8s var(--ease-in-out-smooth),
                transform 0.8s var(--ease-out-expo),
                filter 0.8s var(--ease-in-out-smooth);
    filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.5));
}

.cookie-closed {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    z-index: 2;
}

.cookie-break {
    opacity: 0;
    transform: scale(0.95) rotate(-2deg);
    z-index: 1;
}

.cookie-container.cracked .cookie-closed {
    opacity: 0;
    transform: scale(1.1) rotate(5deg);
    filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.3));
}

.cookie-container.cracked .cookie-break {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    z-index: 2;
}

.cookie-container:not(.cracked) .cookie-closed {
    animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { transform: scale(1) translateY(0); }
    50% { transform: scale(1.015) translateY(-4px); }
}

/* ===== HINT TEXT ===== */
.hint-text {
    margin-top: var(--spacing-lg);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 300;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    opacity: 0;
    animation: fadeInUp 1s var(--ease-out-expo) 0.5s forwards;
    transition: opacity 0.5s ease;
}

.hint-inner {
    display: inline-block;
    background: linear-gradient(90deg, 
        var(--color-text-muted) 0%, 
        var(--color-text-light) 50%, 
        var(--color-text-muted) 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 3s ease-in-out infinite;
}

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

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

.hint-text.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ===== FORTUNE CONTAINER ===== */
.fortune-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--fortune-width);
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s var(--ease-out-expo), visibility 0.6s;
}

.fortune-container.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.fortune-slip {
    position: relative;
    width: 100%;
    transform: translateY(40px) scale(0.9) rotate(-3deg);
    transition: transform 1s var(--ease-out-expo);
    filter: drop-shadow(0 20px 50px rgba(0, 0, 0, 0.6));
}

.fortune-container.visible .fortune-slip {
    transform: translateY(0) scale(1) rotate(0deg);
}

.fortune-frame {
    width: 100%;
    height: auto;
    display: block;
}

/* ===== FORTUNE TEXT - MOBILE-FIRST POSITIONING ===== */
.fortune-text-container {
    position: absolute;
    /* More conservative positioning to avoid frame borders */
    top: 28%;
    left: 22%;
    right: 22%;
    bottom: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4px;
    overflow: hidden;
}

.fortune-text {
    font-family: var(--font-display);
    font-size: var(--fortune-font-size, 0.9rem);
    font-weight: 400;
    font-style: italic;
    line-height: 1.4;
    letter-spacing: 0.01em;
    color: var(--fortune-color, #4a4a4a);
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.15);
    word-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

.lucky-numbers {
    font-family: var(--font-body);
    font-size: clamp(0.55rem, 1.5vw, 0.7rem);
    font-weight: 500;
    letter-spacing: 0.15em;
    margin-top: 6px;
    opacity: 0.9;
    color: var(--fortune-color, #4a4a4a);
    flex-shrink: 0;
    white-space: nowrap;
}

/* Frame-specific colors */
.fortune-slip[data-frame="fun"] {
    --fortune-color: #b03060;
}

.fortune-slip[data-frame="calm"] {
    --fortune-color: #3d5a80;
}

.fortune-slip[data-frame="classic"] {
    --fortune-color: #8b3a3a;
}

/* Frame-specific positioning - Dragon frame needs more side margin */
.fortune-slip[data-frame="classic"] .fortune-text-container {
    left: 26%;
    right: 26%;
}

/* ===== RESTART HINT - MORE PROMINENT ===== */
.restart-hint {
    position: fixed;
    bottom: calc(var(--spacing-lg) + env(safe-area-inset-bottom, 0));
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.7);
    opacity: 0;
    transition: opacity 0.8s ease 0.3s;
    z-index: 50;
    padding: 14px 28px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50px;
    backdrop-filter: blur(15px);
    text-align: center;
    max-width: 90vw;
}

.restart-hint.visible {
    opacity: 1;
    animation: pulseHint 3s ease-in-out infinite;
}

@keyframes pulseHint {
    0%, 100% { 
        transform: translateX(-50%) scale(1);
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.1);
    }
    50% { 
        transform: translateX(-50%) scale(1.02);
        box-shadow: 0 0 20px 5px rgba(255, 255, 255, 0.05);
    }
}

/* ===== PARTICLES ===== */
.particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: radial-gradient(circle, rgba(255, 200, 150, 0.9) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    animation: particleFly 1.5s var(--ease-out-expo) forwards;
}

@keyframes particleFly {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
}

/* ===== TEST PANEL ===== */
.test-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 280px;
    background: rgba(20, 20, 25, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0;
    z-index: 9999;
    font-family: var(--font-body);
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: none;
}

.test-panel.visible {
    display: block;
    animation: slideIn 0.3s var(--ease-out-expo);
}

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

.test-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-light);
}

.test-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.test-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-light);
}

.test-controls {
    padding: 16px;
}

.test-controls label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.test-controls input[type="date"] {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--color-text-light);
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

.test-controls input[type="date"]:focus {
    border-color: var(--color-flamingo);
    box-shadow: 0 0 0 3px rgba(196, 58, 103, 0.2);
}

.test-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.test-buttons button {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: var(--color-text-light);
    font-family: var(--font-body);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.test-buttons button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
}

.test-info {
    margin-top: 16px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    max-height: 150px;
    overflow-y: auto;
}

.test-info strong {
    color: var(--color-text-light);
}

/* ===== RESPONSIVE - MOBILE FIRST ===== */
@media (max-width: 480px) {
    :root {
        --cookie-size: 88vw;
        --fortune-width: 95vw;
    }
    
    .fortune-text-container {
        top: 30%;
        left: 20%;
        right: 20%;
        bottom: 26%;
        padding: 2px;
    }
    
    .fortune-text {
        font-size: var(--fortune-font-size, 0.75rem);
        line-height: 1.35;
    }
    
    .lucky-numbers {
        font-size: 0.5rem;
        margin-top: 4px;
        letter-spacing: 0.1em;
    }
    
    .mood-badge {
        padding: 5px 10px;
        top: calc(var(--spacing-sm) + env(safe-area-inset-top, 0));
    }
    
    .mood-text {
        font-size: 0.6rem;
    }
    
    .mood-icon {
        font-size: 0.9rem;
    }
    
    .test-panel {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
        bottom: 10px;
        font-size: 0.8rem;
    }
    
    .hint-text {
        font-size: 0.75rem;
        margin-top: var(--spacing-md);
    }
    
    .restart-hint {
        font-size: 0.85rem;
        font-weight: 400;
        letter-spacing: 0.05em;
        padding: 12px 20px;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 30px;
        backdrop-filter: blur(10px);
    }
}

@media (min-width: 768px) {
    :root {
        --cookie-size: 400px;
        --fortune-width: 500px;
    }
    
    .fortune-text {
        font-size: 1.15rem;
    }
    
    .lucky-numbers {
        font-size: 0.8rem;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.2s !important;
    }
    
    .ambient-glow { animation: none; }
    .hint-inner { animation: none; background: none; -webkit-text-fill-color: var(--color-text-muted); }
}

/* ===== LANDSCAPE ===== */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --cookie-size: 40vh;
        --fortune-width: 65vw;
    }
    
    .container { padding: var(--spacing-sm); }
    .hint-text { margin-top: var(--spacing-sm); }
}

/* ===== SAFE AREA ===== */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(var(--spacing-md), env(safe-area-inset-left));
        padding-right: max(var(--spacing-md), env(safe-area-inset-right));
    }
}
