/*

Garden:
For usability, a clod of earth has a min dimension 
(e.g. on an iPhone SE I want relatively bigger clods than on a laptop)
But, to be more usable on bigger screens, it also has to grow.
Moreover, I try to exploit the screen the game is played in
So, on a vertical screen I exploit the width and on a horizontal screen I exploit the height.
Lastly, there is a max number of clods
So, after a certain size, the garden stops growing.

*/

:root {
    --max-num-of-rows: 20;
    --max-clods-per-row: 20;
    --min-clod-size: 25px;
    --max-clod-size: 60px;
    
    --clod-size: round(down,
        clamp(var(--min-clod-size), calc(90vw / var(--max-clods-per-row)), var(--max-clod-size)), 
        5px);
    
    --row-width: round(down, 
        min(90vw, calc(var(--max-clods-per-row) * var(--clod-size))), 
        var(--clod-size));
    
    --garden-height: round(down, 
        min(90vh, calc(var(--max-num-of-rows) * var(--clod-size))), 
        var(--clod-size));
}

body {
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgb(66, 81, 66);
}

#garden {
    display: flex;
    flex-direction: column;
    height: var(--garden-height);
    overflow-y: hidden;
    position: relative; /* useful to control the position
    of the snake and of the mouse. */
    box-shadow: 0 0 4px rgb(188, 250, 158);
}

.row {
    display: flex;
    width: var(--row-width);
    height: var(--clod-size);
    min-height: var(--clod-size);
    overflow-x: hidden;
}

.clod {
    width: var(--clod-size);
    min-width: var(--clod-size);
    aspect-ratio: 1;
}

.row:nth-child(even) .clod:nth-child(even),
.row:nth-child(odd) .clod:nth-child(odd) {
    background-color: rgb(160, 222, 124);
}

.row:nth-child(even) .clod:nth-child(odd),
.row:nth-child(odd) .clod:nth-child(even) {
    background-color: rgb(143, 212, 121);
}

@media (max-aspect-ratio: 1/1) { /* (width / height) <= 1 --> vertical */
    #garden {
        border: min(var(--max-clod-size), calc((100vw - var(--row-width)) / 2)) solid rgb(0, 100, 0);
    }
}
@media (min-aspect-ratio: 1/1) { /* horizontal */
    #garden {
        border: min(var(--max-clod-size), calc((100vh - var(--garden-height)) / 2)) solid rgb(0, 100, 0);
    }
}

/*

Snake

*/

.snake-segment {
    width: var(--clod-size);
    aspect-ratio: 1;
    background-color: rgb(255, 120, 0);
    position: absolute;
    box-shadow: 0 0 5px black;
}

#snake-head {
    background-color: rgb(255, 47, 0);
    /* initial position */
    left: round(calc(var(--row-width) / 2), var(--clod-size));
    top: round(calc(var(--garden-height) / 2), var(--clod-size));
    display: flex;
    align-items: end;
    justify-content: space-around;
    rotate: 0deg;
}

#snake-head .eye {
    --eye-width: calc(var(--clod-size) / 4); 
    width: var(--eye-width);
    aspect-ratio: 2/3;
    background-color: white;
    box-shadow: 0 0 1px black;
    border-radius: calc(var(--eye-width)/2);
    margin-bottom: calc(var(--eye-width) / 2);
    display: flex;
    align-items: end;
    justify-content: center;
}

#snake-head .eye:nth-child(1) {
    rotate: -15deg;
}

#snake-head .eye:nth-child(2) {
    rotate: 15deg;
}

#snake-head .pupil {
    width: calc(var(--eye-width) / 4 * 3);
    aspect-ratio: 1;
    background-color: black;
    border-radius: 100%;
    margin: 1px;
}

/*

Mouse

*/

#mouse {
    background-color: rgb(173, 173, 173);
    position: absolute;
    box-shadow: 0 0 1px black;
    width: var(--clod-size);
    aspect-ratio: 1/1;
    left: round(calc(var(--row-width) / 3), var(--clod-size));
    top: round(calc(var(--garden-height) / 3), var(--clod-size));
    display: flex;
    align-items: start;
    justify-content: center;
    flex-wrap: wrap;
    border-top-left-radius: var(--clod-size) calc(var(--clod-size) * 2);
    border-top-right-radius: var(--clod-size) calc(var(--clod-size) * 2);
    clip-path: polygon(0% 0%, 100% 0%, 100% var(--clod-size), 0% var(--clod-size));
}

#mouse .ear {
    width: calc(var(--clod-size)/2);
    aspect-ratio: 1;
    background-color: rgb(173, 173, 173);
    border-radius: 100%;
    box-shadow: inset 0 0 2px black;
}

#mouse .eye {
    background-color: white;
    box-shadow: 0 0 1px black;
    border-radius: 100%;
    width: calc(var(--clod-size)/4);
    aspect-ratio: 1;
    display: flex;
    align-items: end;
    justify-content: end;
}

#mouse .eye:nth-child(even) {
    margin-left: 4px;
    justify-content: start;
}

#mouse .pupil {
    background-color: black;
    border-radius: 100%;
    width: calc(var(--clod-size)/5);
    aspect-ratio: 1;
}

#mouse .paw {
    width: calc(var(--clod-size)/2);
    aspect-ratio: 1;
    background-color: rgb(154, 154, 154);
    border-radius: 100%;
    box-shadow: inset 0 0 1px black;
}

/*

gameover display

*/

#gameover-display {
    position: absolute;
    z-index: 1;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-direction: column;
    background-color: rgba(0, 0, 0, 0.5);
    width: 100vw;
    height: 100vh;
}

#gameover-display > * {
    margin: 0;
}

#gameover-display h2 {
    text-align: center;
    font-size: 5rem;
    color: rgb(198, 43, 43);
    text-shadow: -2px -2px white, -2px 2px white, 2px 2px white, 2px -2px white,
        -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;
}

#gameover-display button {
    font-size: 2rem;
    padding: 1rem;
    cursor: pointer;
    box-shadow: 0 0 3px rgb(227, 227, 227);
    background-color: rgb(198, 43, 43);
    color: white;
    border-radius: 1rem;
}

#gameover-display > div {
    padding: 1rem;
    border-radius: 1rem;
    background-color: aliceblue;
}

#gameover-display p {
    font-size: 2.5rem;
    margin: 0;
    font-weight: bold;
}

#gameover-display p > span {
    font-weight: bold;
    color: black;
}

.display-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
