:root {
    --sky-top: #AEE1F8;
    --sky-bottom: #DDF3FC;
    --sun: #FFF9C4;
    --moon: #F4F6F0;
    --star: #FFF;
    --mountain: #B8D6E8;
    --hill-back: #A7DCA5;
    --hill-front: #88CC85;
    --tree-trunk: #6D4C41;
    --tree-foliage: #4CAF50;
    --grass-dark: #66BB6A;
    --text: #455A64;
    --bg-transition: 3s ease;
}

body.night {
    --sky-top: #0B1026;
    --sky-bottom: #2B32B2;
    --mountain: #1a2340;
    --hill-back: #143625;
    --hill-front: #0d2b1b;
    --tree-trunk: #2d1e1a;
    --tree-foliage: #1b3d1d;
    --grass-dark: #1e3820;
    --text: #B0BEC5;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

body,
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Outfit', sans-serif;
    background-color: var(--sky-top);
    transition: background-color var(--bg-transition);
}

.scene {
    position: relative;
    width: 100%;
    height: 100%;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Sky & Elements */
.sky {
    background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
    z-index: 1;
    transition: background var(--bg-transition);
}

.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(2px 2px at 20px 30px, var(--star), rgba(0, 0, 0, 0)),
        radial-gradient(2px 2px at 40px 70px, var(--star), rgba(0, 0, 0, 0)),
        radial-gradient(2px 2px at 50px 160px, var(--star), rgba(0, 0, 0, 0)),
        radial-gradient(2px 2px at 90px 40px, var(--star), rgba(0, 0, 0, 0)),
        radial-gradient(2px 2px at 130px 80px, var(--star), rgba(0, 0, 0, 0)),
        radial-gradient(2px 2px at 160px 120px, var(--star), rgba(0, 0, 0, 0));
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0;
    transition: opacity var(--bg-transition);
}

body.night .stars {
    opacity: 1;
}

.celestial-container {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: transform var(--bg-transition);
}

.sun {
    position: absolute;
    top: 10%;
    right: 15%;
    width: 80px;
    height: 80px;
    background-color: var(--sun);
    border-radius: 50%;
    box-shadow: 0 0 40px rgba(255, 249, 196, 0.5);
    transition: transform var(--bg-transition), top var(--bg-transition);
}

.moon {
    position: absolute;
    top: 10%;
    left: 15%;
    width: 60px;
    height: 60px;
    background-color: var(--moon);
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    transform: translateY(100vh);
    transition: transform var(--bg-transition);
}

body.night .sun {
    transform: translateY(100vh);
    /* Sets down */
}

body.night .moon {
    transform: translateY(0);
    /* Rises up */
}


.cloud {
    position: absolute;
    background: #fff;
    border-radius: 100px;
    opacity: 0.8;
    animation: floatCloud 60s linear infinite;
}

.cloud::after,
.cloud::before {
    content: '';
    position: absolute;
    background: #fff;
    border-radius: 50%;
}

.cloud-1 {
    top: 15%;
    left: 10%;
    width: 120px;
    height: 40px;
    animation-duration: 45s;
}

.cloud-1::after {
    top: -20px;
    left: 15px;
    width: 50px;
    height: 50px;
}

.cloud-1::before {
    top: -30px;
    left: 45px;
    width: 60px;
    height: 60px;
}

.cloud-2 {
    top: 25%;
    left: 60%;
    width: 100px;
    height: 35px;
    animation-duration: 55s;
}

.cloud-2::after {
    top: -15px;
    left: 10px;
    width: 40px;
    height: 40px;
}

.cloud-3 {
    top: 10%;
    left: 85%;
    width: 140px;
    height: 50px;
    animation-duration: 50s;
}

.cloud-3::after {
    top: -25px;
    left: 20px;
    width: 60px;
    height: 60px;
}

@keyframes floatCloud {
    from {
        transform: translateX(100vw);
    }

    to {
        transform: translateX(-200px);
    }
}

/* Birds */
.bird {
    position: absolute;
    width: 20px;
    height: 10px;
    z-index: 10;
    opacity: 0.7;
    left: -100px;
    /* Hide off-screen initially */
    animation: fly 25s linear infinite;
}

.wing {
    position: absolute;
    top: 5px;
    width: 10px;
    height: 2px;
    background: #546E7A;
    border-radius: 2px;
}

.wing-left {
    right: 50%;
    transform-origin: right center;
    animation: flap-left 0.4s ease-in-out infinite alternate;
}

.wing-right {
    left: 50%;
    transform-origin: left center;
    animation: flap-right 0.4s ease-in-out infinite alternate;
}

.bird-1 {
    top: 15%;
    animation-duration: 35s;
    animation-delay: 0s;
}

.bird-2 {
    top: 20%;
    animation-duration: 40s;
    animation-delay: 15s;
    transform: scale(0.8);
}

.bird-3 {
    top: 10%;
    animation-duration: 30s;
    animation-delay: 5s;
    transform: scale(0.6);
    opacity: 0.5;
}

@keyframes fly {
    from {
        left: -50px;
    }

    to {
        left: 100%;
    }
}

@keyframes flap-left {
    0% {
        transform: rotate(-30deg);
    }

    /* Wing Up */
    100% {
        transform: rotate(10deg);
    }

    /* Wing Down */
}

@keyframes flap-right {
    0% {
        transform: rotate(30deg);
    }

    /* Wing Up */
    100% {
        transform: rotate(-10deg);
    }

    /* Wing Down */
}

/* Mountains */
.mountains {
    z-index: 2;
}

.mountain {
    position: absolute;
    bottom: -10%;
    background-color: var(--mountain);
    border-radius: 50% 50% 0 0;
    transition: background-color var(--bg-transition);
}

.mountain-1 {
    left: -10%;
    width: 60%;
    height: 50%;
}

.mountain-2 {
    right: -10%;
    width: 70%;
    height: 40%;
}

/* Hills */
.hills-back {
    z-index: 3;
}

.hill {
    position: absolute;
    border-radius: 50% 50% 0 0;
    transition: background-color var(--bg-transition);
}

.hill-back-1 {
    bottom: -10%;
    left: -20%;
    width: 80%;
    height: 45%;
    background-color: var(--hill-back);
}

.hill-back-2 {
    bottom: -15%;
    right: -20%;
    width: 60%;
    height: 50%;
    background-color: var(--hill-back);
}

/* Trees - Far */
.tree {
    position: absolute;
    transform-origin: bottom center;
    animation: sway 4s ease-in-out infinite alternate;
    transition: background-color var(--bg-transition);
}

/* Tall/Poplar Tree */
.tree-tall {
    width: 6px;
    height: 40px;
    background: var(--tree-trunk);
}

.tree-tall::after {
    content: '';
    position: absolute;
    bottom: 10px;
    left: -8px;
    width: 22px;
    height: 50px;
    background: #6DBF71;
    border-radius: 50% 50% 50% 50% / 80% 80% 20% 20%;
}

/* Round Tree */
.tree-round {
    width: 8px;
    height: 25px;
    background: var(--tree-trunk);
}

.tree-round::after {
    content: '';
    position: absolute;
    bottom: 15px;
    left: -16px;
    width: 40px;
    height: 40px;
    background: #43A047;
    border-radius: 50%;
}

/* Pine Tree */
.tree-pine {
    width: 6px;
    height: 15px;
    background: var(--tree-trunk);
}

.tree-pine::after {
    content: '';
    position: absolute;
    bottom: 10px;
    left: -12px;
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-bottom: 50px solid #2E7D32;
    border-radius: 0 0 5px 5px;
}

.pos-back-1 {
    bottom: 30%;
    left: 15%;
    animation-delay: 0.5s;
    z-index: -1;
}

.pos-back-2 {
    bottom: 35%;
    left: 25%;
    animation-delay: 1.2s;
    z-index: -1;
    scale: 0.8;
}

.pos-back-3 {
    bottom: 31%;
    right: 25%;
    animation-delay: 2.0s;
    z-index: -1;
}

.pos-back-4 {
    bottom: 35%;
    right: 12%;
    animation-delay: 0.2s;
    z-index: -1;
    scale: 1.2;
}


/* Foreground Hills */
.hills-front {
    z-index: 4;
}

.hill-front-1 {
    bottom: -100px;
    left: -10%;
    width: 120%;
    height: 300px;
    background-color: var(--hill-front);
    border-radius: 50% 50% 0 0;
    border-radius: 200% 200% 0 0 / 100% 100% 0 0;
    transition: background-color var(--bg-transition);
}

/* Hero Tree */
.tree-hero {
    bottom: 160px;
    right: 15%;
    width: 20px;
    height: 120px;
    z-index: 4;
}

.tree-hero .trunk {
    width: 100%;
    height: 100%;
    background: var(--tree-trunk);
    border-radius: 5px;
    transition: background-color var(--bg-transition);
}

.tree-hero .foliage {
    position: absolute;
    bottom: 80px;
    left: -60px;
    width: 140px;
    height: 140px;
    background-color: var(--tree-foliage);
    border-radius: 50%;
    box-shadow: inset -10px -10px 0 rgba(0, 0, 0, 0.05);
    transition: background-color var(--bg-transition);
}

/* Grass Tuft details */
.grass-tuft {
    position: absolute;
    bottom: 0;
    width: 4px;
    height: 15px;
    background: var(--grass-dark);
    border-radius: 2px 2px 0 0;
    transform-origin: bottom center;
    animation: swayFast 2s ease-in-out infinite alternate;
    transition: background-color var(--bg-transition);
}

.tuft-1 {
    bottom: 180px;
    left: 30%;
    height: 12px;
    animation-delay: 0.2s;
}

.tuft-2 {
    bottom: 175px;
    left: 32%;
    height: 18px;
    animation-delay: 0.5s;
}

.tuft-3 {
    bottom: 190px;
    right: 25%;
    height: 14px;
    animation-delay: 0.1s;
}


/* Character Layer */
.character-layer {
    z-index: 10;
}

canvas#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Particles / Foreground FX */
.foreground-fx {
    z-index: 100;
    overflow: hidden;
}

.particle {
    position: absolute;
    top: -20px;
    width: 10px;
    height: 10px;
    background: #FF5252; /* Heart Red/Pink */
    opacity: 0;
    animation: fall linear infinite;
    transform-origin: center;
    --scale: 1;
    transform: rotate(-45deg) scale(var(--scale));
}

.particle::before,
.particle::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: #FF5252;
    border-radius: 50%;
}

.particle::before {
    top: -5px;
    left: 0;
}

.particle::after {
    top: 0;
    left: 5px;
}

.p1 {
    left: 10%;
    animation-duration: 8s;
    animation-delay: 0s;
}

.p2 {
    left: 30%;
    animation-duration: 12s;
    animation-delay: 2s;
    --scale: 0.6;
}

.p3 {
    left: 60%;
    animation-duration: 7s;
    animation-delay: 4s;
    --scale: 0.8;
}

.p4 {
    left: 80%;
    animation-duration: 10s;
    animation-delay: 1s;
    background: #FF8A80;
}
.p4::before, .p4::after { background: #FF8A80; }

.p5 {
    left: 20%;
    animation-duration: 9s;
    animation-delay: 5s;
    background: #FF1744;
}
.p5::before, .p5::after { background: #FF1744; }

@keyframes sway {
    0% {
        transform: rotate(-3deg);
    }

    100% {
        transform: rotate(3deg);
    }
}

@keyframes swayFast {
    0% {
        transform: rotate(-10deg);
    }

    100% {
        transform: rotate(10deg);
    }
}

@keyframes fall {
    0% {
        transform: translate(0, -10px) rotate(-45deg) scale(var(--scale));
        opacity: 0;
    }

    10% {
        opacity: 0.8;
    }

    100% {
        /* Rotate to 315deg makes exactly 1 spin over the duration, preserving the heart orientation! */
        transform: translate(100px, 100vh) rotate(315deg) scale(var(--scale));
        opacity: 0;
    }
}

/* Title Layer */
.title-layer {
    z-index: 150;
}

.title-overlay {
    position: absolute;
    top: 28vh;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-family: 'Fredoka', 'Outfit', sans-serif;
    color: #fff;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: color var(--bg-transition), text-shadow var(--bg-transition);
}

body.night .title-overlay {
    color: #F8BBD0;
    /* Soft pinkish white for the cute theme at night */
    text-shadow: 0 4px 15px rgba(255, 255, 255, 0.15), 0 2px 4px rgba(0, 0, 0, 0.5);
}

.title-overlay h1 {
    font-size: 4.5rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.1;
    letter-spacing: 3px;
}

.title-overlay h2 {
    font-size: 1.8rem;
    font-weight: 600;
    margin: 5px 0 0 0;
    opacity: 0.9;
    letter-spacing: 2px;
}

/* UI / Controls */
.ui-layer {
    z-index: 200;
    position: absolute;
    bottom: 20px;
    left: 20px;
    color: var(--text);
    font-size: 14px;
}

@media (max-width: 600px) {
    .title-overlay {
        top: 22vh;
    }

    .title-overlay h1 {
        font-size: 3rem;
    }

    .title-overlay h2 {
        font-size: 1.2rem;
    }
}

.controls-hint {
    background: rgba(255, 255, 255, 0.7);
    padding: 10px 15px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(5px);
}

.key {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #fff;
    border-radius: 5px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 16px;
}

.key.space {
    width: auto;
    padding: 0 8px;
    font-size: 12px;
    text-transform: uppercase;
}

.touch-controls {
    display: none;
}

@media (pointer: coarse) {

    html,
    body {
        touch-action: none;
    }

    .controls-hint {
        display: none;
        /* Hide keyboard hints */
    }

    .touch-controls {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        position: fixed;
        bottom: 30px;
        left: 20px;
        right: 20px;
        z-index: 300;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    .d-pad {
        display: flex;
        gap: 15px;
    }

    .touch-btn {
        background: rgba(255, 255, 255, 0.4);
        border: 2px solid rgba(255, 255, 255, 0.6);
        color: #fff;
        font-size: 24px;
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        backdrop-filter: blur(5px);
        transform: scale(1);
        transition: transform 0.1s, background 0.1s;
    }

    .touch-btn:active {
        transform: scale(0.9);
        background: rgba(255, 255, 255, 0.6);
    }

    .action-btn {
        width: 80px;
        height: 80px;
        font-size: 18px;
        font-family: inherit;
        font-weight: bold;
        text-transform: uppercase;
    }
}

/* Gravestone */
.gravestone {
    position: absolute;
    bottom: 145px;
    left: 20%;
    width: 50px;
    height: 60px;
    z-index: 5;
    display: flex;
    justify-content: center;
}

.grave-marker {
    width: 44px;
    height: 60px;
    background: #90A4AE;
    border-radius: 22px 22px 0 0;
    box-shadow: inset -5px -5px 0 rgba(0,0,0,0.15);
    position: absolute;
    bottom: 0;
    transition: background-color var(--bg-transition), box-shadow var(--bg-transition);
}

body.night .grave-marker {
    background: #546E7A;
    box-shadow: inset -5px -5px 0 rgba(0,0,0,0.3), 0 0 15px rgba(224, 247, 250, 0.4);
}

.grave-text {
    position: absolute;
    top: 15px;
    color: rgba(255,255,255,0.8);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    transition: text-shadow var(--bg-transition);
}

body.night .grave-text {
    text-shadow: 0 0 8px rgba(224, 247, 250, 0.9);
}

.grave-flower {
    position: absolute;
    background: #F48FB1;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(244,143,177,0.6);
}

.grave-flower.flower-1 {
    width: 14px;
    height: 14px;
    bottom: -2px;
    left: -8px;
}

.grave-flower.flower-1::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 6px;
    height: 6px;
    background: #FFCDD2;
    border-radius: 50%;
}

.grave-flower.flower-2 {
    width: 10px;
    height: 10px;
    bottom: 2px;
    right: -5px;
    background: #CE93D8;
    box-shadow: 0 0 8px rgba(206,147,216,0.6);
}

.grave-flower.flower-2::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 4px;
    height: 4px;
    background: #F3E5F5;
    border-radius: 50%;
}

.grave-flower.flower-3 {
    width: 12px;
    height: 12px;
    bottom: -6px;
    left: 14px;
    background: #FFF59D;
    box-shadow: 0 0 8px rgba(255,245,157,0.6);
}

.grave-flower.flower-3::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 6px;
    height: 6px;
    background: #FFF9C4;
    border-radius: 50%;
}

.grave-flower.flower-4 {
    width: 15px;
    height: 15px;
    bottom: -2px;
    right: 8px;
    background: #FFAB91;
    box-shadow: 0 0 8px rgba(255,171,145,0.6);
}

.grave-flower.flower-4::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 7px;
    height: 7px;
    background: #FFCCBC;
    border-radius: 50%;
}

.grave-flower.flower-5 {
    width: 11px;
    height: 11px;
    bottom: -4px;
    left: 4px;
    background: #81D4FA;
    box-shadow: 0 0 8px rgba(129,212,250,0.6);
}

.grave-flower.flower-5::after {
    content: '';
    position: absolute;
    top: 2.5px;
    left: 2.5px;
    width: 6px;
    height: 6px;
    background: #B3E5FC;
    border-radius: 50%;
}

/* Fireflies / Glowing souls around the grave at night */
.firefly {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #E0F7FA;
    border-radius: 50%;
    opacity: 0;
    box-shadow: 0 0 6px #84FFFF, 0 0 12px #18FFFF;
    pointer-events: none;
    z-index: 10;
    transition: opacity var(--bg-transition);
}

body.night .firefly {
    opacity: 0;
    animation: floatFirefly 4s ease-in-out infinite alternate;
}

@keyframes floatFirefly {
    0% { transform: translateY(0) translateX(0) scale(0.8); opacity: 0; }
    30% { opacity: 0.9; }
    70% { transform: translateY(-25px) translateX(15px) scale(1.2); opacity: 0.9; }
    100% { transform: translateY(-10px) translateX(-10px) scale(0.8); opacity: 0; }
}

body.night .firefly.ff-1 {
    top: -10px;
    left: -15px;
    animation-duration: 5s;
    animation-delay: 0s;
}

body.night .firefly.ff-2 {
    top: -20px;
    right: -10px;
    animation-duration: 6s;
    animation-delay: 2s;
}

body.night .firefly.ff-3 {
    top: -5px;
    left: 20px;
    animation-duration: 4.5s;
    animation-delay: 3.5s;
}