:root {
    --primary: #ff007a;
    --secondary: #00f2ff;
    --accent: #ffeb3b;
    --glass: rgba(0, 0, 0, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
    --px: 0;
    --py: 0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    color: white;
    background: #050515;
}

#bg-sky {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background:
        radial-gradient(ellipse at 85% 8%, rgba(60, 60, 120, 0.25) 0%, transparent 40%),
        radial-gradient(ellipse at 15% 30%, rgba(20, 10, 50, 0.6) 0%, transparent 50%),
        radial-gradient(circle at center, #0a0a2e 0%, #030310 100%);
    z-index: 0;
}

#stars-container, #clouds-container {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 1;
    pointer-events: none;
}

#stars-container {
    transform: translate(calc(var(--px) * -10px), calc(var(--py) * -5px)) scale(1.05);
}

#clouds-container {
    transform: translate(calc(var(--px) * -5px), calc(var(--py) * -2px)) scale(1.05);
}

.cloud {
    position: absolute;
    background: white;
    filter: blur(10px);
    border-radius: 50%;
    opacity: 0.15;
    animation: drift var(--duration) infinite linear;
}

@keyframes drift {
    from { transform: translateX(-200px); }
    to { transform: translateX(calc(100vw + 200px)); }
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle var(--duration) infinite ease-in-out;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.5); }
}

#moon {
    position: fixed;
    top: 25px;
    right: 30px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    z-index: 2;
    transform: translate(calc(var(--px) * -15px), calc(var(--py) * -10px));
    background: radial-gradient(circle at 40% 38%, #fff8dc 0%, #ffe9a0 50%, #f0c850 100%);
    box-shadow:
        0 0 20px 5px rgba(255, 240, 150, 0.3),
        0 0 60px 15px rgba(255, 230, 100, 0.12),
        inset -8px -5px 0 rgba(230, 180, 60, 0.25);
    animation: moon-float 6s ease-in-out infinite;
}

@keyframes moon-float {
    0%, 100% { transform: translate(calc(var(--px) * -15px), calc(var(--py) * -10px)) translateY(0); }
    50% { transform: translate(calc(var(--px) * -15px), calc(var(--py) * -10px)) translateY(-5px); }
}

.moon-face {
    position: relative;
    width: 100%;
    height: 100%;
}

/* --- Eyes --- */
.moon-eye {
    position: absolute;
    top: 32px;
    width: 10px;
    height: 12px;
    background: #3a2a15;
    border-radius: 50%;
    animation: moon-blink 8s infinite;
}
.moon-eye.left { left: 24px; }
.moon-eye.right { right: 24px; }

@keyframes moon-blink {
    0%, 42%, 46%, 100% { 
        height: 12px; 
        top: 32px;
        border-radius: 50%;
    }
    44% { 
        height: 2px; 
        top: 37px;
        border-radius: 50%;
    }
    /* Sleepy/yawn phase — half-closed eyes */
    70%, 88% {
        height: 5px;
        top: 36px;
        border-radius: 40% 40% 50% 50%;
    }
}

/* --- Blush Cheeks --- */
.moon-blush {
    position: absolute;
    top: 42px;
    width: 14px;
    height: 8px;
    background: rgba(255, 130, 130, 0.35);
    border-radius: 50%;
    filter: blur(2px);
}
.moon-blush.left { left: 14px; }
.moon-blush.right { right: 14px; }

/* --- Mouth (Smile ↔ Yawn cycle) --- */
.moon-mouth {
    position: absolute;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 10px;
    border: 2.5px solid transparent;
    border-bottom: 2.5px solid #8a5a20;
    border-radius: 0 0 50% 50%;
    animation: moon-mouth-cycle 8s infinite;
}

@keyframes moon-mouth-cycle {
    /* Happy smile */
    0%, 55% {
        width: 20px;
        height: 10px;
        bottom: 22px;
        border-bottom: 2.5px solid #8a5a20;
        border-left: 2.5px solid transparent;
        border-right: 2.5px solid transparent;
        border-top: none;
        border-radius: 0 0 50% 50%;
        background: transparent;
    }
    /* Transition to yawn */
    65% {
        width: 14px;
        height: 14px;
        bottom: 20px;
        border: 2.5px solid #8a5a20;
        border-radius: 50%;
        background: rgba(100, 50, 20, 0.3);
    }
    /* Full yawn (big open mouth) */
    72%, 82% {
        width: 18px;
        height: 18px;
        bottom: 18px;
        border: 2.5px solid #8a5a20;
        border-radius: 50%;
        background: rgba(100, 50, 20, 0.35);
    }
    /* Closing yawn */
    90% {
        width: 14px;
        height: 10px;
        bottom: 21px;
        border: 2.5px solid #8a5a20;
        border-radius: 50%;
        background: rgba(100, 50, 20, 0.15);
    }
    /* Back to smile */
    95%, 100% {
        width: 20px;
        height: 10px;
        bottom: 22px;
        border-bottom: 2.5px solid #8a5a20;
        border-left: 2.5px solid transparent;
        border-right: 2.5px solid transparent;
        border-top: none;
        border-radius: 0 0 50% 50%;
        background: transparent;
    }
}

/* --- Hands --- */
.moon-hand {
    position: absolute;
    top: 50%;
    font-size: 18px;
    transform-origin: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 3;
    pointer-events: none;
}
.moon-hand.left {
    left: -22px;
    transform: translateY(-50%) scaleX(-1) rotate(0deg);
}
.moon-hand.right {
    right: -22px;
    transform: translateY(-50%) rotate(0deg);
}

/* When moon is excited (firework explodes) */
#moon.excited .moon-hand {
    opacity: 1;
}
#moon.excited .moon-hand.left {
    animation: clap-left 0.3s ease-in-out 4;
}
#moon.excited .moon-hand.right {
    animation: clap-right 0.3s ease-in-out 4;
}

@keyframes clap-left {
    0%, 100% { left: -22px; transform: translateY(-50%) scaleX(-1) rotate(-15deg); }
    50% { left: -5px; transform: translateY(-50%) scaleX(-1) rotate(15deg); }
}
@keyframes clap-right {
    0%, 100% { right: -22px; transform: translateY(-50%) rotate(-15deg); }
    50% { right: -5px; transform: translateY(-50%) rotate(15deg); }
}

/* Excited face — overrides default idle animations */
#moon.excited .moon-eye {
    animation: none !important;
    height: 13px;
    width: 11px;
    top: 30px;
    border-radius: 50%;
    background: #3a2a15;
}
/* Little star sparkle in the eyes */
#moon.excited .moon-eye::after {
    content: '✦';
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 6px;
    color: #fff;
    animation: eye-sparkle 0.5s ease infinite alternate;
}
@keyframes eye-sparkle {
    0% { opacity: 0.5; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1.2); }
}

#moon.excited .moon-mouth {
    animation: none !important;
    width: 24px;
    height: 14px;
    bottom: 18px;
    border-bottom: 3px solid #8a5a20;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: none;
    border-radius: 0 0 50% 50%;
    background: transparent;
}

#moon.excited .moon-blush {
    background: rgba(255, 100, 100, 0.5);
    width: 16px;
    height: 10px;
}

/* --- Moon Text Bubble --- */
#moon-text-bubble {
    position: absolute;
    bottom: -45px;
    left: 50%;
    transform: translateX(-50%) translateY(10px) scale(0.5);
    background: #ffffff;
    color: #ff007a;
    padding: 6px 14px;
    border-radius: 15px;
    font-size: 14px;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 5px 20px rgba(255, 255, 255, 0.4);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 5;
}

#moon-text-bubble::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 6px 6px 6px;
    border-style: solid;
    border-color: transparent transparent #ffffff transparent;
}

#moon.excited #moon-text-bubble {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
    animation: bubble-float 2s ease-in-out infinite alternate;
}

@keyframes bubble-float {
    0% { transform: translateX(-50%) translateY(0) scale(1); }
    100% { transform: translateX(-50%) translateY(4px) scale(1); }
}

#fireworksCanvas {
    position: fixed;
    top: 0; left: 0;
    z-index: 10;
}

#landscape {
    position: fixed;
    bottom: 25vh; left: 0; width: 100%; height: 80px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 100" preserveAspectRatio="none"><path d="M0 100 L0 80 Q100 60 200 80 T400 70 T600 90 T800 60 T1000 80 L1000 100 Z" fill="%230a0a20"/></svg>');
    background-size: 100% 100%;
    z-index: 20;
    transform: translate(calc(var(--px) * 20px), calc(var(--py) * 10px)) scale(1.05);
    transform-origin: bottom center;
}

#lake {
    position: fixed;
    bottom: 0; left: 0;
    width: 100%;
    height: 25vh;
    z-index: 15;
    overflow: hidden;
    /* Richer deep water blue with wave texture */
    background: 
        repeating-linear-gradient(
            to bottom,
            transparent,
            transparent 3px,
            rgba(200, 220, 255, 0.03) 4px,
            transparent 5px
        ),
        linear-gradient(to bottom, #060b20 0%, #02040a 100%);
    border-top: 2px solid rgba(100, 150, 255, 0.15);
    box-shadow: inset 0 10px 20px rgba(0, 0, 0, 0.8);
    transform: translate(calc(var(--px) * 10px), calc(var(--py) * 5px)) scale(1.05);
    transform-origin: bottom center;
}

/* Subtle moving moonlight reflection on the water to make it look alive */
#lake::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(ellipse at 85% 0%, rgba(200, 220, 255, 0.15) 0%, transparent 60%);
    animation: gentle-waves 4s infinite alternate ease-in-out;
    pointer-events: none;
    z-index: 1;
}

@keyframes gentle-waves {
    0% { opacity: 0.6; transform: scaleX(1); }
    100% { opacity: 1; transform: scaleX(1.05) translateX(-2%); }
}

#waterCanvas {
    position: absolute;
    left: 0;
    top: -25vh;
    width: 100vw;
    height: 100vh;
    transform: scaleY(-1);
    opacity: 0.55;
    filter: blur(2px);
    animation: water-ripple 4s infinite ease-in-out alternate;
}

@keyframes water-ripple {
    0% { transform: scaleY(-1) scaleX(1); }
    100% { transform: scaleY(-1) scaleX(1.02) translateY(2px); }
}

/* --- Swimming Animals --- */
.swimming-duck, .swimming-fish {
    position: absolute;
    z-index: 2; /* Above the canvas reflection */
    pointer-events: none;
    user-select: none;
    will-change: left, top, transform; /* Optimize for JS animation */
}

.swimming-duck {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
    opacity: 0.9;
}

.swimming-fish.fish1 {
    font-size: 16px;
    opacity: 0.4; /* Faint to look underwater */
}

.swimming-fish.fish2 {
    font-size: 12px;
    opacity: 0.3;
}

#launcher {
    position: fixed;
    bottom: calc(25vh + 10px);
    left: 50%;
    transform: translateX(calc(-50% + var(--px) * 20px)) translateY(calc(var(--py) * 10px));
    width: 40px;
    height: 25px;
    background: linear-gradient(to top, #111, #4a4e69);
    border: 2px solid #888;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    z-index: 25;
    box-shadow: 0 0 20px rgba(100, 200, 255, 0.3), inset 0 5px 10px rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

#launcher::after {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 8px;
    background: #ffcc00;
    border-radius: 50%;
    box-shadow: 0 0 15px #ffaa00, 0 0 30px #ff5500;
    animation: launcher-glow 1.5s infinite alternate;
}

@keyframes launcher-glow {
    0% { opacity: 0.7; box-shadow: 0 0 10px #ffaa00; }
    100% { opacity: 1; box-shadow: 0 0 25px #ffcc00, 0 0 40px #ff5500; }
}

#ui-container {
    position: fixed;
    bottom: 15px; /* Extremely close to the bottom edge */
    left: 0;
    width: 100%;
    z-index: 100;
    display: flex;
    justify-content: center;
    padding: 0 10px;
    pointer-events: none;
}

#ui-container.hidden { display: none; }

#controls {
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: all;
    background: rgba(20, 15, 35, 0.5); /* Slightly more transparent */
    padding: 4px 6px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    max-width: 100%;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.mode-selector {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-right: 10px;
    /* Smooth scrolling for mobile */
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, black 85%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
}

.mode-selector::-webkit-scrollbar { display: none; }

.mode-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    padding: 6px 10px;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Outfit', sans-serif;
}

.mode-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.mode-btn.active {
    background: linear-gradient(135deg, #ff007a, #7a00ff);
    color: white;
    box-shadow: 0 2px 8px rgba(255, 0, 122, 0.4);
    font-weight: 700;
    transform: scale(1.05);
}

.action-btns {
    display: flex;
    gap: 5px;
    border-left: 1px solid rgba(255,255,255,0.1);
    padding-left: 6px;
}

#finale-btn, #sound-btn, #fullscreen-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

#sound-btn:hover, #fullscreen-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

#finale-btn {
    background: linear-gradient(135deg, #ffcc00, #ff6600);
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.4);
    font-size: 0.95rem;
}

#finale-btn:hover {
    box-shadow: 0 0 25px rgba(255, 204, 0, 0.8);
    transform: scale(1.15) rotate(15deg);
}

/* Game Style Overlay */
#overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(5, 5, 20, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    transition: opacity 0.5s ease;
}

.intro-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 50px;
}

.magical-core {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 25px;
}

.core-star {
    font-size: 1.5rem;
    animation: core-pulse 2s infinite alternate ease-in-out;
    filter: drop-shadow(0 0 10px #ff007a) drop-shadow(0 0 20px #00f2ff);
}

.core-ring {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.core-ring.r1 {
    width: 40px; height: 40px;
    border-top-color: #ff007a;
    border-bottom-color: #00f2ff;
    animation: spin 3s infinite linear;
}

.core-ring.r2 {
    width: 55px; height: 55px;
    border-left-color: #ffcc00;
    border-right-color: #ff007a;
    animation: spin 4s infinite linear reverse;
    opacity: 0.6;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes core-pulse {
    0% { transform: scale(0.8); opacity: 0.8; }
    100% { transform: scale(1.3); opacity: 1; }
}

.intro-title {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 8px;
    background: linear-gradient(135deg, #ffffff, #ffeb3b, #00f2ff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 5px 15px rgba(255, 255, 255, 0.2);
    margin-bottom: 8px;
    text-align: center;
    animation: gradient-flow 3s linear infinite;
}

@keyframes gradient-flow {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.intro-subtitle {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 4px;
    text-align: center;
    text-transform: uppercase;
    font-weight: 500;
}

#start-btn {
    position: relative;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 10px 35px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 30px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 3px;
    backdrop-filter: blur(5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#start-btn:hover {
    transform: scale(1.1);
    background: #ffffff;
    color: #111122; /* Dark text on hover so it's visible */
    box-shadow: 0 5px 25px rgba(255, 255, 255, 0.4);
}

#start-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Screen Shake Effect */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shake {
    animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

#flash-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #ffffff;
    z-index: 150;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

#flash-overlay.active {
    opacity: 0.8;
    transition: none;
}

#name-modal, #draw-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 300;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#name-modal.hidden, #draw-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #111122;
    padding: 30px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    text-align: center;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#name-modal.hidden .modal-content, #draw-modal.hidden .modal-content {
    transform: scale(0.8);
}

.modal-content h3 {
    margin-bottom: 20px;
    color: #fff;
    font-size: 1.5rem;
}

#name-input {
    width: 100%;
    padding: 12px 15px;
    font-size: 1.2rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: #fff;
    outline: none;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    text-transform: uppercase;
}

#name-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(255, 0, 122, 0.5);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 25px;
}

.modal-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Outfit', sans-serif;
}

#name-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

#name-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

#name-submit {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 0, 122, 0.4);
}

#name-submit:hover, #draw-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 0, 122, 0.6);
}

#draw-pad {
    background: #050510;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    cursor: crosshair;
    touch-action: none; /* Prevent scrolling while drawing */
}
