/* Reset y diseño básico */
* {
    box-sizing: border-box;
}

body {
    background: var(--sky-gradient, linear-gradient(to bottom, #a3d9ff 0%, #e0f6ff 100%));
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    position: relative;
    transition: background 2s ease;
}

.ground {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 25vh;
    background: var(--ground-color, #689f38);
    z-index: -1;
    border-top: 5px solid var(--ground-border, #558b2f);
    transition: background 2s ease, border-color 2s ease;
}

.garden {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateY(22vh);
    transform-origin: bottom center;
    /* Ajustado para que descanse sobre el pasto */
}

/* Contenedor principal de los tulipanes y maceta */
.plant-container {
    position: relative;
    width: 250px;
    height: 380px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.pot {
    position: absolute;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    /* Maceta más ancha para 5 tulipanes */
    height: 80px;
    background: linear-gradient(to right, #ba6d3c, #da864d);
    border-radius: 5px 5px 25px 25px;
    box-shadow: inset 0px -8px 20px rgba(0, 0, 0, 0.12), 0 10px 15px rgba(0, 0, 0, 0.2);
    z-index: 20;
}

.pot::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    /* Borde de maceta más ancho */
    height: 20px;
    background: linear-gradient(to right, #cc7844, #e59155);
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.pot-label {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #5c351f;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    font-size: 1.1rem;
    text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.4), -1px -1px 0px rgba(0, 0, 0, 0.2);
    width: 90%;
    text-align: center;
    line-height: 1.1;
    z-index: 25;
}

/* Posiciones base para los 5 Tulipanes */
.tulip {
    position: absolute;
    bottom: 50px;
    width: 8px;
    height: 0px;
    transform-origin: bottom center;
}

.tulip-far-left {
    left: calc(50% - 45px);
    /* Más juntos al centro */
    transform: rotate(-22deg);
    /* Menos inclinados para no separar las flores */
    z-index: 4;
}

.tulip-left {
    left: calc(50% - 22px);
    transform: rotate(-10deg);
    z-index: 5;
}

.tulip-center {
    left: calc(50% - 4px);
    bottom: 55px;
    /* Ligeramente más arriba */
    z-index: 10;
}

.tulip-right {
    left: calc(50% + 14px);
    transform: rotate(10deg);
    z-index: 5;
}

.tulip-far-right {
    left: calc(50% + 37px);
    transform: rotate(22deg);
    /* Menos inclinados para agrupar las flores */
    z-index: 4;
}

/* Tallo */
.stem {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 8px;
    height: 0px;
    background: linear-gradient(to right, #2e7d32, #4caf50);
    border-radius: 4px;
    transform-origin: bottom center;
    transition: height 1.5s ease-in-out;
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2);
}

/* Hojas - Base */
.leaf {
    position: absolute;
    width: 40px;
    height: 90px;
    background: linear-gradient(to top right, #388e3c, #4caf50);
    border-radius: 50% 0 50% 0;
    opacity: 0;
    transform: scale(0) rotate(0deg);
    transition: transform 0.8s ease-in, opacity 0.5s;
    z-index: 6;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.1), 0 5px 5px rgba(0, 0, 0, 0.15);
}

.leaf.left {
    transform-origin: bottom right;
    right: 8px;
    border-radius: 0 50% 0 50%;
}

.leaf.right {
    transform-origin: bottom left;
    left: 8px;
}

/* Posicionamiento Vertical Individual de Hojas */
.tulip-center .leaf {
    bottom: -10px;
    /* Bajar más las hojas centrales (ocultar un poco en la maceta) */
}

.tulip-left .leaf,
.tulip-right .leaf {
    bottom: 55px;
}

.tulip-far-left .leaf,
.tulip-far-right .leaf {
    bottom: 85px;
    /* Super elevadas para que nazcan directamente desde arriba del borde */
}

/* Flor Container */
.flower {
    position: absolute;
    bottom: 0px;
    left: -31px;
    width: 70px;
    height: 80px;
    transform-origin: bottom center;
    transform: scale(0);
    opacity: 0;
    transition: bottom 1.5s ease-in-out, transform 0.8s ease-in, opacity 0.8s;
    z-index: 15;
    filter: drop-shadow(0px 5px 5px rgba(251, 192, 45, 0.4));
}

/* Pétalos AMARILLOS */
.petal {
    position: absolute;
    bottom: 0;
    background: radial-gradient(circle at bottom, #fff59d, #fbc02d);
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1);
}

.petal-center {
    width: 45px;
    height: 75px;
    left: 12.5px;
    border-radius: 50% 50% 20% 20%;
    z-index: 3;
    background: radial-gradient(circle at bottom, #fff9c4, #f9a825);
}

.petal-left {
    width: 45px;
    height: 70px;
    left: -5px;
    border-radius: 50% 10% 20% 50%;
    transform: rotate(-18deg);
    z-index: 2;
}

.petal-right {
    width: 45px;
    height: 70px;
    right: -5px;
    border-radius: 10% 50% 50% 20%;
    transform: rotate(18deg);
    z-index: 2;
}

.petal-center::after {
    content: '';
    position: absolute;
    bottom: 12px;
    left: 17.5px;
    width: 10px;
    height: 35px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    filter: blur(3px);
}

/* ================== ESTADOS DE ANIMACIÓN (GROWING) ================== */

/* Tulipán Extremo Izquierdo */
.plant-container.growing .tulip-far-left .stem {
    height: 150px;
    transition: height 2.1s ease-in-out;
}

.plant-container.growing .tulip-far-left .flower {
    bottom: 140px;
    opacity: 1;
    transform: scale(0.75);
    transition: bottom 2.1s ease-in-out, transform 1s ease-out 2.1s, opacity 1s 2.1s;
}

.plant-container.growing .tulip-far-left .leaf.left {
    transition: transform 1.5s ease-out 0.9s, opacity 1s 0.9s;
    opacity: 1;
    transform: scale(0.65) rotate(-55deg);
}

.plant-container.growing .tulip-far-left .leaf.right {
    transition: transform 1.5s ease-out 1.2s, opacity 1s 1.2s;
    opacity: 1;
    transform: scale(0.65) rotate(55deg);
}

/* Tulipán Izquierdo */
.plant-container.growing .tulip-left .stem {
    height: 190px;
    transition: height 2.5s ease-in-out;
}

.plant-container.growing .tulip-left .flower {
    bottom: 180px;
    opacity: 1;
    transform: scale(0.9);
    transition: bottom 2.5s ease-in-out, transform 1.2s ease-out 2.5s, opacity 1s 2.5s;
}

.plant-container.growing .tulip-left .leaf.left {
    transition: transform 1.5s ease-out 1.2s, opacity 1s 1.2s;
    opacity: 1;
    transform: scale(0.75) rotate(-45deg);
}

.plant-container.growing .tulip-left .leaf.right {
    transition: transform 1.5s ease-out 1.5s, opacity 1s 1.5s;
    opacity: 1;
    transform: scale(0.75) rotate(45deg);
}

/* Tulipán Central */
.plant-container.growing .tulip-center .stem {
    height: 240px;
    transition: height 2.7s ease-in-out;
}

.plant-container.growing .tulip-center .flower {
    bottom: 230px;
    opacity: 1;
    transform: scale(1);
    transition: bottom 2.7s ease-in-out, transform 1.5s ease-out 2.7s, opacity 1s 2.7s;
}

.plant-container.growing .tulip-center .leaf.left {
    transition: transform 1.5s ease-out 1.4s, opacity 1s 1.4s;
    opacity: 1;
    transform: scale(0.9) rotate(-40deg);
}

.plant-container.growing .tulip-center .leaf.right {
    transition: transform 1.5s ease-out 1.8s, opacity 1s 1.8s;
    opacity: 1;
    transform: scale(0.9) rotate(40deg);
}

/* Tulipán Derecho */
.plant-container.growing .tulip-right .stem {
    height: 190px;
    transition: height 2.3s ease-in-out;
}

.plant-container.growing .tulip-right .flower {
    bottom: 180px;
    opacity: 1;
    transform: scale(0.9);
    transition: bottom 2.3s ease-in-out, transform 1.2s ease-out 2.3s, opacity 1s 2.3s;
}

.plant-container.growing .tulip-right .leaf.left {
    transition: transform 1.5s ease-out 1.1s, opacity 1s 1.1s;
    opacity: 1;
    transform: scale(0.75) rotate(-45deg);
}

.plant-container.growing .tulip-right .leaf.right {
    transition: transform 1.5s ease-out 1.3s, opacity 1s 1.3s;
    opacity: 1;
    transform: scale(0.75) rotate(45deg);
}

/* Tulipán Extremo Derecho */
.plant-container.growing .tulip-far-right .stem {
    height: 150px;
    transition: height 2.0s ease-in-out;
}

.plant-container.growing .tulip-far-right .flower {
    bottom: 140px;
    opacity: 1;
    transform: scale(0.75);
    transition: bottom 2.0s ease-in-out, transform 1s ease-out 2.0s, opacity 1s 2.0s;
}

.plant-container.growing .tulip-far-right .leaf.left {
    transition: transform 1.5s ease-out 0.8s, opacity 1s 0.8s;
    opacity: 1;
    transform: scale(0.65) rotate(-55deg);
}

.plant-container.growing .tulip-far-right .leaf.right {
    transition: transform 1.5s ease-out 1.0s, opacity 1s 1.0s;
    opacity: 1;
    transform: scale(0.65) rotate(55deg);
}

/* ================== ESTILOS DEL BOTON ================== */
#action-btn {
    margin-top: 50px;
    padding: 14px 28px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
    background: #f57f17;
    /* Color cálido/amaranto para combinar */
    border: none;
    border-radius: 40px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(245, 127, 23, 0.4);
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    z-index: 30;
}

#action-btn:hover {
    background: #e65100;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 127, 23, 0.5);
}

#action-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 10px rgba(245, 127, 23, 0.3);
}

#action-btn:disabled {
    background: #ccc;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* ================== DEBUG PANEL ================== */
.debug-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 15px 20px;
    border-radius: 10px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 1rem;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.debug-panel input[type="range"] {
    width: 200px;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* ================== AMBIENTE (ESTRELLAS, SOL/LUNA, NUBES Y PASTO) ================== */

/* --- Cielo Estrellado (Noche) --- */
.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: -2;
    opacity: 0;
    transition: opacity 3s ease;
}

body.time-night .stars {
    opacity: 1;
    /* Solo visibles de noche */
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle infinite alternate;
}

@keyframes twinkle {
    0% {
        opacity: 0.2;
        transform: scale(0.8);
    }

    100% {
        opacity: 1;
        transform: scale(1.2);
        box-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
    }
}

/* --- Estrella Fugaz --- */
.shooting-star {
    position: absolute;
    width: 100px;
    height: 2px;
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
    border-radius: 50%;
    transform: rotate(155deg); /* Apuntar cabeza hacia abajo-izquierda */
    pointer-events: none;
    z-index: -2;
    opacity: 0;
}

/* La estrella fugaz solo se anima (aparece esporádicamente) si es de noche */
body.time-night .shooting-star {
    animation: shooting 12s infinite 4s linear;
}

@keyframes shooting {
    0% {
        top: 0vh; /* Nace desde el techo a la derecha */
        left: 100vw;
        transform: rotate(155deg) translateX(0);
        opacity: 0;
    }

    5% {
        opacity: 1;
    }

    20% {
        top: 0vh;
        left: 100vw;
        /* Al rotar 155 grados (izquierda y abajo) y trasladar positivamente, la estrella cae cruzando todo */
        transform: rotate(155deg) translateX(200vmax); 
        opacity: 0;
    }

    100% {
        top: 0vh;
        left: 100vw;
        transform: rotate(155deg) translateX(200vmax);
        opacity: 0;
    }
}

/* --- Sol / Luna --- */
.celestial-body {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: -1;

    /* Variables controladas por el tema (JS) */
    background: var(--celestial-bg, #fff59d);
    box-shadow: var(--celestial-glow, 0 0 80px 30px rgba(255, 235, 59, 0.6));
    top: var(--celestial-top, 15vh);
    left: var(--celestial-left, 50vw);

    /* Animación de transición suave entre horas */
    transition: top 3s ease-in-out, left 3s ease-in-out, background 3s ease, box-shadow 3s ease;
}

/* --- Nubes --- */
.clouds {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.cloud {
    position: absolute;
    background: #fff;
    border-radius: 50px;
    opacity: 0.8;
    filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.05));
    animation: floatCloud linear infinite;
}

.cloud::before,
.cloud::after {
    content: '';
    position: absolute;
    background: #fff;
    border-radius: 50%;
}

.cloud-1 {
    width: 120px;
    height: 40px;
    top: 15%;
    left: -150px;
    animation-duration: 40s;
    animation-delay: 0s;
}

.cloud-1::before {
    width: 50px;
    height: 50px;
    top: -25px;
    left: 15px;
}

.cloud-1::after {
    width: 70px;
    height: 70px;
    top: -35px;
    right: 15px;
}

.cloud-2 {
    width: 100px;
    height: 35px;
    top: 35%;
    left: -150px;
    opacity: 0.6;
    animation-duration: 55s;
    animation-delay: 15s;
    --cloud-scale: 0.8;
}

.cloud-2::before {
    width: 40px;
    height: 40px;
    top: -20px;
    left: 15px;
}

.cloud-2::after {
    width: 60px;
    height: 60px;
    top: -30px;
    right: 15px;
}

.cloud-3 {
    width: 150px;
    height: 45px;
    top: 10%;
    left: -200px;
    opacity: 0.9;
    animation-duration: 45s;
    animation-delay: 25s;
    --cloud-scale: 1.2;
}

.cloud-3::before {
    width: 60px;
    height: 60px;
    top: -30px;
    left: 20px;
}

.cloud-3::after {
    width: 80px;
    height: 80px;
    top: -40px;
    right: 20px;
}

.cloud-4 {
    width: 90px;
    height: 30px;
    top: 25%;
    left: -150px;
    opacity: 0.5;
    animation-duration: 35s;
    animation-delay: 5s;
    --cloud-scale: 0.7;
}

.cloud-4::before {
    width: 35px;
    height: 35px;
    top: -15px;
    left: 10px;
}

.cloud-4::after {
    width: 50px;
    height: 50px;
    top: -25px;
    right: 10px;
}

@keyframes floatCloud {
    0% {
        transform: translateX(-200px) scale(var(--cloud-scale, 1));
    }

    100% {
        transform: translateX(calc(100vw + 400px)) scale(var(--cloud-scale, 1));
    }
}

/* --- Brotes de Pasto --- */
.grass {
    position: absolute;
    bottom: 100%;
    /* Justo por encima del borde del .ground */
    width: 6px;
    background: linear-gradient(to top, #388e3c, #558b2f);
    border-radius: 5px 5px 0 0;
    transform-origin: bottom center;
    animation: sway 2.5s ease-in-out infinite alternate;
}

/* Hoja de pasto izquierda */
.grass::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -5px;
    width: 4px;
    height: 70%;
    background: linear-gradient(to top, #2e7d32, #4caf50);
    border-radius: 4px 4px 0 0;
    transform-origin: bottom center;
    transform: rotate(-25deg);
}

/* Hoja de pasto derecha */
.grass::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -4px;
    width: 4px;
    height: 80%;
    background: linear-gradient(to top, #1b5e20, #388e3c);
    border-radius: 4px 4px 0 0;
    transform-origin: bottom center;
    transform: rotate(25deg);
}

@keyframes sway {
    0% {
        transform: rotate(-8deg);
    }

    100% {
        transform: rotate(8deg);
    }
}

/* ================== TEMPORADAS DEL DÍA (DYNAMIC THEMES) ================== */

body.time-dawn {
    --sky-gradient: linear-gradient(to bottom, #ff9a9e 0%, #fecfef 100%);
    --ground-color: #5d9b4b;
    --ground-border: #4a7d3c;
    /* Sol amaneciendo */
    --celestial-bg: #ffeb3b;
    --celestial-glow: 0 0 60px 20px rgba(255, 152, 0, 0.4);
    --celestial-top: 50vh;
    --celestial-left: 20vw;
}

body.time-day {
    --sky-gradient: linear-gradient(to bottom, #a3d9ff 0%, #e0f6ff 100%);
    --ground-color: #689f38;
    --ground-border: #558b2f;
    /* Sol en lo alto */
    --celestial-bg: #fff59d;
    --celestial-glow: 0 0 80px 30px rgba(255, 235, 59, 0.6);
    --celestial-top: 15vh;
    --celestial-left: 50vw;
}

body.time-afternoon {
    --sky-gradient: linear-gradient(to bottom, #fd5e0f 0%, #ff9e7a 50%, #ffd060 100%);
    --ground-color: #557d2d;
    --ground-border: #42631f;
    /* Sol atardeciendo */
    --celestial-bg: #ff9800;
    --celestial-glow: 0 0 70px 25px rgba(244, 67, 54, 0.5);
    --celestial-top: 45vh;
    --celestial-left: 80vw;
}

body.time-night {
    --sky-gradient: linear-gradient(to bottom, #020111 0%, #20124d 50%, #000022 100%);
    --ground-color: #1a2e12;
    --ground-border: #111e0b;
    /* Luna */
    --celestial-bg: #f5f3ce;
    --celestial-glow: 0 0 50px 15px rgba(255, 255, 255, 0.3), inset -15px -15px 0 0 rgba(0, 0, 0, 0.1);
    --celestial-top: 20vh;
    --celestial-left: 70vw;
}

/* Oscurecer las nubes en la noche */
body.time-night .cloud {
    background: #aab;
    opacity: 0.2 !important;
}

body.time-night .cloud::before,
body.time-night .cloud::after {
    background: #aab;
}

/* ================== RESPONSIVE DESIGN ================== */

/* Tablets (hasta 768px) */
@media (max-width: 768px) {
    .garden {
        transform: translateY(18vh) scale(0.85);
        /* Escalar sin elevar de la tierra, pero ajustando la base hacia arriba ligeramente */
    }

    #action-btn {
        margin-top: 40px;
        padding: 12px 24px;
        font-size: 1.1rem;
    }
}

/* Teléfonos móviles pequeños (hasta 480px) */
@media (max-width: 480px) {
    .garden {
        transform: translateY(16vh) scale(0.7);
        /* Escalar manteniendo el ancla en el suelo, subiéndola lo justo para no verse hundida */
    }

    #action-btn {
        margin-top: 30px;
        padding: 10px 20px;
        font-size: 1rem;
    }
}

/* ================== PARTICULAS DE TULIPAN ================== */
#particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    /* Por encima de las flores */
}

.magic-particle {
    position: absolute;
    border-radius: 50%;
    /* El background (color) se asienta vía JS para que caiga en la gama de amarillos */
    box-shadow: 0 0 6px 2px rgba(255, 255, 255, 0.4);
    opacity: 0;
    animation: floatParticle linear forwards;
}

@keyframes floatParticle {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0.5);
    }

    20% {
        opacity: 0.8;
    }

    80% {
        opacity: 0.6;
    }

    100% {
        opacity: 0;
        transform: translateY(-80px) scale(1.5);
    }
}