/* ---------------------------------- */
/* 1. FONT IMPORT & ROOT VARIABLES    */
/* ---------------------------------- */

@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Fredoka:wght@400;700&display=swap');

:root {
    /* Fonts */
    --font-primary: 'Luckiest Guy', cursive; /* For the main word, very playful */
    --font-secondary: 'Fredoka', sans-serif; /* For UI elements, very readable */

    /* Core Colors */
    --color-bg: #f0f8ff; /* Alice Blue */
    --color-text: #333;
    --color-dark: #1a2c42;
    --color-light: #ffffff;

    /* Sizing */
    --card-width: 300px;
    --card-height: 420px;
    --border-radius: 20px;
}

/* ---------------------------------- */
/* 2. GENERAL & LAYOUT STYLING        */
/* ---------------------------------- */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-secondary);
    background-color: #fee440; /* New background color */
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 80px 20px 20px; /* extra top padding for fixed header */
    overflow-x: hidden;
    overflow-y: auto; /* allow scrolling */

}

svg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: -1; /* Place it behind all content */
}

/* Ensure header and other main elements have a higher z-index */
header, #game-container {
    position: relative;
    z-index: 1;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center; /* Vertically align items */
    gap: 20px;
    padding: 10px 20px;
    background-color: #fee440;
    transition: transform 0.3s ease;
}

header.hidden-header {
    transform: translateY(-100%);
}

header h1 {
    margin: 0; /* Remove default margins */
    font-style: normal;
}

header button {
    flex-shrink: 0; /* Prevent buttons from shrinking */
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: normal;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

#new-game-btn.hidden {
    display: none;
}

button {
    font-family: var(--font-secondary);
    font-weight: 700;
    font-size: 16px;
    padding: 12px 24px;
    border: none;
    border-radius: 50px;
    background-color: var(--color-light);
    color: #ff6b6b;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#timer-display {
    font-family: var(--font-primary);
    font-size: 4rem;
    color: var(--color-dark);
    text-shadow: 3px 3px 0px var(--color-light);
}

/* ---------------------------------- */
/* 3. CARD FLIP & AREA              */
/* ---------------------------------- */

#card-area {
    width: var(--card-width);
    height: var(--card-height);
    perspective: 1500px; /* Essential for the 3D flip effect */
    margin-bottom: 7px;
    position: relative; /* Ensure child cards are positioned correctly */
}

.card {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: transform 0.8s ease-in-out;
    transform-style: preserve-3d;
    backface-visibility: hidden; /* Hides the back of the element when flipped */
    border-radius: var(--border-radius);
    border: 4px solid #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 15px;
}

#card-area.is-flipped #card-deck {
    transform: rotateY(180deg);
}

#card-area.is-flipped #card-display {
    transform: rotateY(0deg);
}

/* ---------------------------------- */
/* 4. CARD DECK STYLING (FACE-DOWN)   */
/* ---------------------------------- */

#card-deck {
    transform: rotateY(0deg);
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: 1.8rem;
    color: #b8860b;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    position: relative;
    z-index: 1;
}

/* Stacked cards effect */
#card-deck::before,
#card-deck::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: var(--border-radius);
    top: 0;
    left: 0;
    z-index: -1;
    transition: transform 0.3s ease;
}

#card-deck::before {
    transform: rotate(-5deg);
}
#card-deck::after {
    transform: rotate(5deg);
}

#card-deck:hover::before { transform: rotate(-8deg) translateY(-10px); }
#card-deck:hover::after { transform: rotate(8deg) translateY(-10px); }

/* --- Deck Color Themes (to be set by JS) --- */
.deck-theme-red { background: linear-gradient(135deg, #ff758c, #ff7eb3); }
.deck-theme-red::before, .deck-theme-red::after { background: linear-gradient(135deg, #ff758c, #ff7eb3); }

.deck-theme-blue { background: linear-gradient(135deg, #74ebd5, #ACB6E5); }
.deck-theme-blue::before, .deck-theme-blue::after { background: linear-gradient(135deg, #74ebd5, #ACB6E5); }

.deck-theme-purple { background: linear-gradient(135deg, #89f7fe, #66a6ff); }
.deck-theme-purple::before, .deck-theme-purple::after { background: linear-gradient(135deg, #89f7fe, #66a6ff); }

.deck-theme-orange { background: linear-gradient(135deg, #f6d365, #fda085); }
.deck-theme-orange::before, .deck-theme-orange::after { background: linear-gradient(135deg, #f6d365, #fda085); }

/* --- CORRECCIÓN PARA OCULTAR TEXTO DEL REVERSO --- */
#card-area.is-flipped #card-deck {
    color: transparent;
    text-shadow: none;
}


/* ---------------------------------- */
/* 5. CARD DISPLAY STYLES (FACE-UP)   */
/* ---------------------------------- */

#card-display {
    transform: rotateY(-180deg); /* Start flipped away */
    gap: 15px;
    z-index: 2;
}
#card-display.hidden {
    display: none; /* Initial state before game starts */
}

#card-display #emoji {
    font-size: 4.32rem;
    line-height: 1;
}

#card-display #word {
    font-family: var(--font-primary);
    font-size: 2.88rem;
    line-height: 1.1;
    text-transform: uppercase;
    writing-mode: vertical-lr;
    text-orientation: upright;
    direction: rtl;
}


#card-display #level {
    font-size: 0.864rem;
    font-weight: 700;
    padding: 5px 15px;
    border-radius: 20px;
    position: absolute;
    top: 20px;
    right: 20px;
}

/* Style 1: Comic Book Pop! */
.card-style-1 {
    background-color: #ffd166;
    color: var(--color-dark);
    box-shadow: 10px 10px 0px #06d6a0;
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
.card-style-1 #word { text-shadow: 3px 3px 0 #ef476f; }
.card-style-1 #level { background-color: #118ab2; color: var(--color-light); }

/* Style 2: Neon Glow */
.card-style-2 {
    background-color: #1D1029;
    color: #fff;
    animation: fadeIn 0.5s;
}
.card-style-2 #word {
    color: #fff;
    text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 20px #f92a82, 0 0 30px #f92a82;
}
.card-style-2 #emoji { filter: drop-shadow(0 0 10px #f92a82); }
.card-style-2 #level { background-color: #f92a82; color: var(--color-light); }

/* Style 3: Wobbly Jelly */
.card-style-3 {
    background: rgba(135, 207, 235, 0.8);
    backdrop-filter: blur(5px);
    color: var(--color-dark);
    animation: jiggle 0.6s;
}
.card-style-3 #word { text-shadow: 2px 2px 0px rgba(255,255,255,0.7); }
.card-style-3 #level { background-color: rgba(255,255,255,0.5); color: var(--color-dark); }

/* Style 4: Retro Gradient */
.card-style-4 {
    background: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%);
    color: var(--color-light);
    animation: fadeIn 0.5s;
}
.card-style-4 #word { text-shadow: 3px 3px 2px rgba(0,0,0,0.2); }
.card-style-4 #level { background-color: transparent; border: 2px solid var(--color-light); }

/* Style 5: Hand-Drawn Sketch */
.card-style-5 {
    background-color: #faf8f0;
    border-radius: 15px 255px 20px 225px / 225px 20px 255px 15px; /* Quirky border */
    color: #444;
    animation: fadeIn 0.5s;
}
.card-style-5 #word { color: #e63946; }
.card-style-5 #level { background-color: #a8dadc; color: var(--color-dark); }

/* Style 6: Sticker Peel */
.card-style-6 {
    background-color: #fff;
    color: var(--color-dark);
    filter: drop-shadow(5px 8px 5px rgba(0,0,0,0.2));
    transform: rotate(-3deg);
    animation: popIn 0.3s;
}
.card-style-6 #word { color: #457b9d; }
.card-style-6 #level { background-color: #f1faee; color: #1d3557; border: 2px solid #1d3557; }

/* Style 7: Minimalist Invert */
.card-style-7 {
    background-color: var(--color-dark);
    color: var(--color-light);
    animation: fadeIn 0.5s;
}
.card-style-7 #word { color: #96e6a1; text-shadow: none; }
.card-style-7 #level { background-color: var(--color-light); color: var(--color-dark); }


/* ---------------------------------- */
/* 6. CONTROLS & RESPONSIVENESS       */
/* ---------------------------------- */

#controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 0;
    background: rgba(255, 255, 255, 0.5);
    padding: 15px 25px;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    color: #ff6b6b;
}

#controls label {
    font-weight: 700;
    font-size: 1rem;
    color: #ff6b6b;
}

#controls input {
    font-family: var(--font-primary);
    width: 80px;
    padding: 8px;
    font-size: 1.5rem;
    text-align: center;
    border: 2px solid #ddd;
    border-radius: 10px;
    background-color: var(--color-light);
}

/* --- NEW CSS for Action Buttons --- */
#action-buttons {
    display: flex;
    gap: 20px;
    margin-top: 5px;
}

#action-buttons.hidden {
    display: none;
}

#action-buttons button {
    font-family: var(--font-primary);
    font-size: 1.6rem;
    padding: 12px 32px;
    border-radius: 12px;
    border: 4px solid var(--color-dark);
    color: var(--color-light);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.2);
}
#divider {
    width: 100%;
    max-width: 600px;
    border: none;
    border-top: 2px dashed rgba(0,0,0,0.2);
    margin: 20px 0;
}

#buttons-divider {
    width: 100%;
    max-width: 600px;
    border: none;
    border-top: 2px dashed rgba(0,0,0,0.2);
    margin: 5px 0;
}

#pass-btn {
    background-color: #ef476f;
}

#correct-btn {
    background-color: #06d6a0;
}

/* Media Query for smaller screens */
@media (max-width: 480px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
    }
    :root {
        --card-width: 260px;
        --card-height: 360px;
    }
    #timer-display { font-size: 3rem; }
    #card-display #emoji { font-size: 2.88rem; }
    #card-display #word { font-size: 2.016rem; }
    #card-display #level { font-size: 0.72rem; top: 10px; right: 10px; }
    #controls { flex-direction: column; padding: 15px; border-radius: 20px; }

    header {
        flex-direction: column;
        gap: 10px;
    }
    header h1 {
        font-size: 2.2rem;
        order: -1;
    }
    .header-buttons {
        display: flex;
        gap: 15px;
        width: 100%;
        justify-content: space-between;
    }
    header button {
        padding: 8px 16px;
        font-size: 14px;
    }

    /* CRITICAL STYLES FOR STATS ALIGNMENT */
    #stats-container {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 20px;
        width: 100%;
        order: -1;
    }

    #timer-display {
        font-size: 3.5rem;
        text-shadow: 2px 2px 0px var(--color-light);
    }

    #score-display {
        font-size: 2rem;
        padding: 8px 25px;
        margin-bottom: 0;
        order: 2;
    }

    #game-container {
        gap: 15px;
    }

    #card-area {
        margin-bottom: 0;
    }

    #buttons-divider, #divider {
        margin: 5px 0;
    }

    #action-buttons {
        gap: 15px;
        margin-top: 0;
    }

    #action-buttons button {
        font-size: 1.2rem;
        padding: 10px 25px;
    }

    /* Reduce size of category buttons */
    .level-options label,
    #tag-options-container label {
        font-size: 0.5rem;
        padding: 4px 6px;
    }
}


/* ---------------------------------- */
/* 7. KEYFRAME ANIMATIONS             */
/* ---------------------------------- */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    75% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); }
}

@keyframes jiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-2deg); }
    75% { transform: rotate(2deg); }
}

/* --- NEW KEYFRAME ANIMATION --- */
@keyframes gradientAnimation {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Estilo para el contenedor de puntos */
#score-display {
    font-family: var(--font-primary);
    font-size: 2.5rem;
    color: var(--color-light);
    background: linear-gradient(135deg, #89f7fe, #66a6ff);
    padding: 10px 30px;
    border-radius: 50px;
    border: 4px solid var(--color-light);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15), inset 0 -4px 0 rgba(0,0,0,0.2);
    margin-bottom: 10px;
    text-shadow: 2px 2px 3px rgba(0,0,0,0.25);
    transition: transform 0.2s ease;
}

#score-display.hidden {
    display: none;
}

/* Highlight final score with a bright halo */
.final-score {
    background: linear-gradient(135deg, #f6d365, #fda085);
    box-shadow: 0 0 15px 5px rgba(255, 175, 75, 0.7);
}

/* Clase para activar la animación de pulso */
.score-pulse {
    animation: scoreUpdate 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Animación Keyframe para el pulso */
@keyframes scoreUpdate {
    0% { transform: scale(1); }
    50% { transform: scale(1.25) rotate(-5deg); }
    100% { transform: scale(1); }
}

/* --- También añade esta línea para que el marcador no aparezca hasta que empiece el juego --- */
#game-container #score-display {
    display: none; /* Oculto por defecto */
}
#game-container.game-active #score-display {
    display: block; /* Visible cuando el juego está activo */
}

/* ---------------------------------- */
/* 8. OPTIONS MODAL STYLES            */
/* ---------------------------------- */

#options-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

#options-modal.hidden {
    display: none;
}

#options-content {
    background: var(--color-light);
    border-radius: var(--border-radius);
    padding: 25px 35px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 500px;
    text-align: center;
    position: relative;
    font-family: var(--font-secondary);
    border: 4px solid #ff6b6b;
    animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

#options-content h3 {
    font-family: var(--font-primary);
    font-size: 2.5rem;
    color: #ff6b6b;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

.options-section {
    margin-bottom: 20px;
}

.options-section > span {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--color-dark);
    display: block;
    margin-bottom: 10px;
}

/* Alignment for level header with toggle button */
.options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.options-header > span {
    margin-bottom: 0;
}

/* Level & Tag Options */
.level-options, #tag-options-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

#tag-options-container {
    max-height: 150px;
    overflow-y: auto;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 10px;
}


.level-options label,
#tag-options-container label {
    display: flex;
    align-items: center;
    background: #f7f7f7;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.level-options label:has(input:checked),
#tag-options-container label:has(input:checked) {
    background-color: #06d6a0;
    color: var(--color-light);
    font-weight: 700;
}

#options-content input[type="radio"],
#options-content input[type="checkbox"] {
    margin-right: 8px;
}


/* Time Input */
#options-content #time-input {
    font-family: var(--font-primary);
    width: 100px;
    font-size: 2rem;
    text-align: center;
    border: 3px solid #ddd;
    border-radius: 10px;
    padding: 5px;
}

/* Action Buttons */
#options-content #toggle-all-btn,
#options-content #start-game-btn {
    font-family: var(--font-primary);
    font-size: 1.5rem;
    padding: 12px 30px;
    border-radius: 12px;
    margin-top: 10px;
    width: auto;
    color: var(--color-light);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.2);
    border: 3px solid var(--color-dark);
}

#options-content #toggle-all-btn {
    background-color: #118ab2;
}

#options-content #start-game-btn {
    background-color: #06d6a0;
    width: 80%;
    margin-top: 20px;
}

#close-options-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    background-color: #06d6a0;
    color: var(--color-light);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
}

header h1 {
    font-family: var(--font-primary);
    color: var(--color-light);
    text-shadow: 3px 3px 0px #ff6b6b;
    font-size: 2.5rem;
}

