@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap');

:root {
    --bg-color: #3498DB;
    --card-color: #f1c40f;
    --monster-color: #8E44AD;
    --text-color: #2c3e50;
    --accent-color: #e74c3c;
}

body {
    font-family: 'Fredoka One', cursive;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    color: var(--text-color);
    text-align: center;
}

#app-container {
    background: #fff;
    padding: 2rem;
    border-radius: 25px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2), 0 6px 6px rgba(0,0,0,0.25);
    border: 5px solid var(--text-color);
    max-width: 400px;
    width: 90%;
}

h1 {
    color: var(--monster-color);
    text-shadow: 2px 2px 0 var(--card-color);
    margin-bottom: 0.5rem;
}

#joke-counter {
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 1rem;
}

#joke-count {
    font-weight: bold;
    color: var(--monster-color);
}

/* --- Giggles The Monster --- */
#giggles-container {
    height: 150px;
    position: relative;
    margin-bottom: 1rem;
}

#giggles {
    width: 120px;
    height: 120px;
    background: var(--monster-color);
    border-radius: 50%;
    border: 4px solid var(--text-color);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    animation: idle-bounce 2s infinite ease-in-out;
}

/* Giggles' Animations */
@keyframes idle-bounce {
    0%, 100% { transform: translate(-50%, 0); }
    50% { transform: translate(-50%, -15px); }
}

@keyframes tell-joke {
    0% { transform: translate(-50%, 0) scale(1); }
    25% { transform: translate(-50%, 10px) rotate(-15deg) scale(0.9); }
    50% { transform: translate(-50%, 0) rotate(15deg) scale(1.1); }
    75% { transform: translate(-50%, -10px) rotate(0deg) scale(1); }
    100% { transform: translate(-50%, 0); }
}

@keyframes happy-react {
    0%, 100% { transform: translate(-50%, 0) rotate(0deg); }
    50% { transform: translate(-50%, -30px) rotate(360deg); }
}

@keyframes groan-react {
    0%, 100% { transform: translate(-50%, 0) rotate(0deg); }
    50% { transform: translate(-50%, 10px) rotate(0deg); opacity: 0.6; }
}

#giggles.telling { animation: tell-joke 0.7s ease-in-out; }
#giggles.happy { animation: happy-react 0.8s ease-in-out; }
#giggles.groan { animation: groan-react 0.8s ease-in-out; }

/* Giggles' Features */
.eye {
    width: 60px;
    height: 60px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    overflow: hidden;
    border: 3px solid var(--text-color);
}
.pupil {
    width: 25px;
    height: 25px;
    background: var(--text-color);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s;
}
.mouth {
    width: 50px;
    height: 20px;
    background: var(--text-color);
    border-radius: 0 0 50px 50px;
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}
.antenna {
    width: 6px;
    height: 30px;
    background: var(--monster-color);
    border: 2px solid var(--text-color);
    position: absolute;
    top: -20px;
    border-radius: 5px;
    transition: transform 0.5s;
}
.antenna::after {
    content: '';
    width: 15px;
    height: 15px;
    background: var(--card-color);
    border: 2px solid var(--text-color);
    border-radius: 50%;
    position: absolute;
    top: -10px;
    left: -6px;
}
.antenna-left { left: 30px; transform: rotate(-15deg); }
.antenna-right { right: 30px; transform: rotate(15deg); }

#giggles.groan .antenna { transform: rotate(0deg) translateY(10px); }

/* --- Joke Card --- */
#joke-card {
    background: var(--card-color);
    padding: 1.5rem;
    border-radius: 15px;
    border: 4px solid var(--text-color);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 1rem 0;
    transition: transform 0.3s, opacity 0.3s;
}
#joke-card.loading {
    opacity: 0;
    transform: scale(0.9);
}
#joke-setup { font-size: 1.2rem; }
#joke-punchline { font-size: 1.3rem; margin-top: 1rem; font-weight: bold; opacity: 0; transition: opacity 0.5s ease-in 0.5s; }
#joke-punchline.visible { opacity: 1; }

/* --- Controls --- */
#get-joke-btn {
    background-color: var(--accent-color);
    color: white;
    border: 4px solid var(--text-color);
    padding: 1rem 2rem;
    font-family: 'Fredoka One', cursive;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}
#get-joke-btn:hover { transform: translateY(-3px); box-shadow: 0 4px 8px rgba(0,0,0,0.2); }
#get-joke-btn:active { transform: translateY(1px); }
#get-joke-btn:disabled { background-color: #95a5a6; cursor: not-allowed; }

#groan-o-meter-container {
    margin-top: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
#groan-o-meter-container span { font-size: 2rem; }
#rating {
    -webkit-appearance: none;
    width: 60%;
    height: 15px;
    border-radius: 10px;
    background: linear-gradient(to right, #2ecc71, #f1c40f, #e74c3c);
    outline: none;
    border: 3px solid var(--text-color);
}
#rating::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: var(--monster-color);
    cursor: pointer;
    border: 3px solid white;
}


/* ========================================= */
/*      MOBILE RESPONSIVENESS (The Magic)    */
/* ========================================= */

/* This applies the styles inside only when the screen width is 480px or less. */
/* ========================================= */
/*      MOBILE RESPONSIVENESS (FULL SCREEN)  */
/* ========================================= */

/* This applies the styles inside only when the screen width is 480px or less. */
@media (max-width: 480px) {

    body {
        /* Remove vertical centering to allow the app container to sit at the top */
        align-items: flex-start;
    }

    #app-container {
        /* Make the container fill the entire screen */
        min-height: 100vh;
        width: 100%;
        max-width: 100%; /* Override any desktop max-width */
        
        /* Remove the card-like appearance */
        border-radius: 0;
        border: none;
        box-shadow: none;

        /* Ensure padding is calculated correctly within the full height */
        box-sizing: border-box;
        
        /* Use flexbox to organize the header and main content */
        display: flex;
        flex-direction: column;
    }
    
    main {
        /* This is the key to the new layout! */
        display: flex;
        flex-direction: column;
        justify-content: space-around; /* Distributes elements vertically */
        flex-grow: 1; /* Allows the main area to fill all available space */
        padding-bottom: 1rem; /* Adds a little space at the very bottom */
    }

    header {
        flex-shrink: 0; /* Prevents the header from shrinking */
    }

    h1 {
        font-size: 1.8rem;
    }

    /* --- Adjusting Giggles --- */
    #giggles-container {
        height: 120px;
        margin-bottom: 0; /* Spacing is now handled by justify-content */
    }

    #giggles {
        width: 100px;
        height: 100px;
    }
    .eye { width: 50px; height: 50px; top: 20px; }
    .pupil { width: 20px; height: 20px; }
    .mouth { width: 40px; height: 15px; bottom: 18px; }
    .antenna-left { left: 25px; }
    .antenna-right { right: 25px; }

    /* --- Adjusting Joke Card & Text --- */
    #joke-card {
        padding: 1rem;
        min-height: 100px;
        margin-left: 1rem;  /* Add side margins */
        margin-right: 1rem; /* Add side margins */
    }
    #joke-setup { font-size: 1.1rem; }
    #joke-punchline { font-size: 1.2rem; }

    /* --- Adjusting Controls --- */
    #get-joke-btn {
        font-size: 1rem;
        padding: 0.8rem 1.5rem;
    }
    
    #groan-o-meter-container {
        margin-top: 0; /* Spacing handled by justify-content */
    }

    #groan-o-meter-container span {
        font-size: 1.8rem;
    }
}