:root {
    --color-primary: #FF9EAA;
    /* Soft pink */
    --color-primary-dark: #F48FB1;
    --color-secondary: #90CAF9;
    /* Soft blue */
    --color-accent: #FFF59D;
    /* Soft yellow */
    --color-bg: #FFF0F5;
    --color-card: #FFFFFF;
    --color-text: #8D6E63;
    /* Brownish text, warm */
    --color-border: #FFCDD2;
    --font-main: 'Outfit', sans-serif;
    --shadow: 0 10px 25px rgba(255, 158, 170, 0.25);
    --shadow-hover: 0 15px 35px rgba(255, 158, 170, 0.35);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    /* Polka dot pattern */
    background-image: radial-gradient(#FFCDD2 15%, transparent 16%), radial-gradient(#F8BBD0 15%, transparent 16%);
    background-size: 40px 40px;
    background-position: 0 0, 20px 20px;
    color: var(--color-text);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 10px;
    /* Reduced padding */
    /* Glassmorphism card effect */
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    margin: 0 auto;
    position: relative;
    box-shadow: 0 0 50px rgba(255, 255, 255, 0.5);
    overflow-y: auto;
    /* Allow scrolling if screen is too small */
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: white;
    border-radius: 25px;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 100;
}

.icon-btn {
    background: #FFF9C4;
    /* Yellowish button */
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy */
    box-shadow: 0 4px 0 #FDD835;
}

.icon-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #FDD835;
}

.language-selector {
    display: flex;
    gap: 12px;
}

.flag-btn {
    background: transparent;
    border: 3px solid transparent;
    border-radius: 18px;
    padding: 2px;
    cursor: pointer;
    transition: all 0.2s;
    width: 60px;
    height: 45px;
    opacity: 0.6;
    transform: scale(0.9);
}

.flag-btn.active {
    border-color: var(--color-primary);
    opacity: 1;
    transform: scale(1.1);
    background: white;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.flag-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 12px;
}

/* Screens */
#game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    justify-content: center;
    padding: 20px;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.screen.active {
    display: flex;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Title & Hero */
.kawaii-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 3.5rem;
    color: var(--color-primary);
    text-shadow: 4px 4px 0px white, 6px 6px 0px var(--color-border);
    margin-bottom: 20px;
    letter-spacing: -1px;
}

.kawaii-subtitle {
    font-size: 1.4rem;
    color: var(--color-secondary);
    margin-bottom: 25px;
    font-weight: bold;
    transform: rotate(-2deg);
    text-shadow: 1px 1px 0 white;
}

.hero-img {
    width: 140px;
    margin-bottom: 30px;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.1));
}

.floating {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-15px) rotate(3deg);
    }
}

/* Buttons */
.btn-primary {
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 30px;
    padding: 15px 50px;
    font-size: 1.6rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 0 var(--color-primary-dark), 0 15px 25px rgba(255, 158, 170, 0.4);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
    touch-action: manipulation;
    position: relative;
    z-index: 200;
    pointer-events: auto !important;
}

.icon-btn,
.flag-btn {
    position: relative;
    z-index: 200;
}

.btn-secondary {
    background: var(--color-secondary);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 12px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 0 #64B5F6;
    margin: 10px;
    transition: all 0.2s;
}

.btn-secondary:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #64B5F6;
}

/* Game Info */
.score-container {
    background: white;
    padding: 10px 25px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    display: inline-flex;
    gap: 10px;
    font-size: 1.8rem;
    color: var(--color-text);
    font-weight: 800;
    margin-bottom: 20px;
    border: 3px solid var(--color-bg);
}

#label-score {
    color: var(--color-primary);
}

/* Canvas Wrapper */
.canvas-wrapper {
    position: relative;
    background: white;
    border: 6px solid var(--color-border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    /* 
       CRITICAL FIX: 
       Subtract the approximate height of other elements (Header + Score + Controls + Padding) 
       Header (~70px) + Score (~60px) + Controls (~120px) + Padding (~30px) = ~280px
    */
    max-width: 300px;
    /* Use the smaller of: 300px OR Available viewport height minus UI elements */
    max-height: calc(100vh - 300px);
    aspect-ratio: 1/1;
    margin: 0 auto;
    overflow: hidden;
    flex-shrink: 1;
    /* Allow shrinking */
    touch-action: none;
    /* Critical for swipe control */
}

#game-canvas {
    background-color: #ffffff;
    display: block;
    width: 100%;
    height: 100%;
}

/* Mobile Instructions */
.mobile-instruction {
    display: none;
    /* Hidden by default (desktop) */
    text-align: center;
    margin-top: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 15px;
    border: 2px dashed var(--color-border);
}

#instruction-text {
    font-size: 1.2rem;
    color: var(--color-primary);
    font-weight: bold;
    animation: pulseText 2s infinite;
}

@keyframes pulseText {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

@media (pointer: coarse) {
    .touch-controls {
        display: none;
        /* Ensure old class is hidden just in case */
    }

    .mobile-instruction {
        display: block;
    }

    .canvas-wrapper {
        margin-bottom: 0;
    }
}

/* Game Over Overlay */
#game-over-screen {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(255, 255, 255, 0.98);
    padding: 15px;
    border-radius: 20px;
    border: 4px solid var(--color-primary);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    width: 80%;
    max-width: 260px;
    /* Narrower */
    max-height: 70vh;
    /* Shorter limit */
    overflow-y: auto;
    display: none;
    flex-direction: column;
    /* Ensure stacked layout */
    align-items: center;
    /* Center content */
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#game-over-screen.active {
    display: flex;
    animation: popInModal 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popInModal {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

#game-over-title {
    font-size: 1.4rem;
    /* Smaller */
    color: var(--color-primary);
    text-shadow: 1px 1px 0 var(--color-accent);
    margin-bottom: 5px;
    font-weight: 900;
    line-height: 1.2;
}

.final-score {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--color-text);
    font-weight: bold;
    background: var(--color-bg);
    padding: 5px 10px;
    border-radius: 8px;
}

.game-over-img {
    width: 50px;
    /* Tiny image */
    margin-bottom: 10px;
    animation: shake 2s infinite;
}

.btn-primary {
    padding: 10px 30px;
    /* Smaller buttons */
    font-size: 1.2rem;
    margin: 8px;
}

.btn-secondary {
    padding: 8px 20px;
    font-size: 1rem;
    margin: 5px;
}

@keyframes shake {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-5deg);
    }

    75% {
        transform: rotate(5deg);
    }
}

/* Footer */
.game-footer {
    text-align: center;
    font-size: 0.9rem;
    color: #BCAAA4;
    margin-top: 10px;
    font-weight: bold;
}

/* --- MEJORAS PARA MÓVILES --- */

/* Instrucciones móviles */
.mobile-instruction {
    display: none;
    text-align: center;
    margin-top: 15px;
    padding: 10px;
    background: rgba(255, 158, 170, 0.2);
    border-radius: 8px;
    font-weight: bold;
    color: var(--color-primary-dark);
}

@media (max-width: 768px) {
    .mobile-instruction {
        display: block;
    }
}
