/**

RACE CAR

The goal of this game is to drive the car on the road, avoiding the grease stains that would make the car lose control and crash.

Place the mouse on the screen and avoid the black stains while staying on the road.

GAME CONFIGURATION

--speed: speed of the animation. The lower the number, the faster the game will go. Default value: 10;

--timing: the animation timing function. Default linear (everything moves at the same speed). Other values: ease, or a bezier function.

--animation: indicates the number of laps/loops that the game will execute. 0=paused game/animations; infinite=continuous game.

*/
:root {
  --speed: 20;
  --timing: linear;
  --animation: infinite;
}

/*
To make the game low resolution (it will load faster and be smoother), uncomment the  following lines:

html::before,
html::after,
body {
  background-image: none !important;
  box-shadow: none !important;
}
body {
  background: black;
}
*/

html {
  display: block;
  position: absolute;
  overflow: hidden;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background-image: 
    linear-gradient(#4f38, transparent),
    linear-gradient(skyblue 40%, #384 0);
  perspective: 500px;
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='75px' height='75px' viewBox='0 0 100 100'><ellipse cx='50' cy='95' rx='50' ry='5' fill='rgba(0,0,0,0.1)'/><path d='M5,60 25,60 25,100 5,100Z' fill='%23222' /><path d='M75,60 95,60 95,100 75,100Z' fill='%23222' /><rect x='2' y='45' width='96' height='35' fill='%2312b' rx='3' ry='3' /><path d='M20,10 80,10 90,50 10,50Z' fill='skyblue' stroke='%2312b' stroke-width='6' /><path d='M0,45 100,45 100,55 0,55Z' fill='navy'/><path d='M5,55 15,55 15,60 5,60Z' fill='orange'/><path d='M95,55 85,55 85,60 95,60Z' fill='orange'/><path d='M15,55 25,55 25,60 15,60Z' fill='red'/><path d='M85,55 75,55 75,60 85,60Z' fill='red'/><path d='M35,68 65,68 65,75 35,75Z' fill='white'/><circle cx='50' cy='60' r='2' fill='gray' /></svg>") 31 31, pointer;
}

@keyframes moveRoad {
  0% { background-position: 0 0; }
  100% { background-position: 0 16.3vh; }
}

html::before {
  content: "";
  display: block;
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 50vw;
  height: 163vh;
  transform-origin: bottom center;
  transform: translate(-50%, 0) rotate3d(1, 0, 0, 60deg);
  background-color: gray;
  background-image: linear-gradient(to right, transparent 10%, gray 0 90%, transparent 0),
    repeating-linear-gradient(white 0 5%, #c00 0 10%);
  box-shadow: 0 0 30vmin #fd8c;
  animation: moveRoad calc(var(--speed) * 0.0175s) linear var(--animation);
}

html::after {
  content: "";
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 40vh;
  background: skyblue;
  background-image:
    radial-gradient(circle at 80% 120%, #281 20%, transparent 0),
    radial-gradient(circle at 115% 140%, #172 34%, transparent 0),
    radial-gradient(circle at 75% 20%, #ffe 10%, #fff 15%, transparent 70%),
    radial-gradient(circle, green 70%, transparent 0),
    radial-gradient(circle, green 50%, transparent 0),
    linear-gradient(brown, brown),
    linear-gradient(45deg, gray 50%, transparent 0),
    linear-gradient(120deg, transparent 50%, gray 0)
    ;
  background-size: 
    100% 100%, 
    100% 100%, 
    100% 100%,
    6vmin 6vmin,
    6vmin 6vmin,
    1vmin 5vmin,
    20vmin 20vmin,
    20vmin 20vmin;
  background-position:
    0 0,
    0 0,
    0 0,
    6.5vmin calc(100% - 4vmin),
    6.5vmin calc(100% - 7vmin),
    9vmin 100%,
    20vmin 100%,
    0vmin 100%;
  background-repeat: no-repeat;
}

@keyframes moveObstacles {
  0% { transform: translate(-50%, 0) rotate3d(1, 0, 0, 60deg) translate(0, -20%); }
  100% { transform: translate(-50%, 0) rotate3d(1, 0, 0, 60deg) translate(0, 100%); }
}

body {
  display: block;
  position: fixed;
  bottom: 0;
  left: 50%;
  width: 100vw; /* 40vw; */
  height: 800vh;
  margin: 0;
  padding: 0;
  border: 0;
  transform-origin: bottom center;
  transform: translate(-50%, 0) rotate3d(1, 0, 0, 60deg);
  animation: moveObstacles calc(var(--speed) * 1s) var(--timing) var(--animation);
  animation-fill-mode: forwards;
  clip-path: polygon(
    52% 100%, 52% 95%, 0% 95%,
    0% 80%, 52% 80%, 52% 75%, 0% 75%,
    0% 60%, 52% 60%, 52% 55%, 0% 55%,
    0% 40%, 52% 40%, 52% 35%, 0% 35%,
    0% 20%, 52% 20%, 52% 15%, 0% 15%,
    0% 0%, -500% 0%, -500% -500%, 
    500% -500%, 500% 0%, 100% 0%, 
    100% 5%, 48% 5%, 48% 10%, 100% 10%,
    100% 25%, 47% 25%, 47% 30%, 100% 30%,
    100% 45%, 47% 45%, 47% 50%, 100% 50%,
    100% 65%, 47% 65%, 47% 70%, 100% 70%,
    100% 85%, 47% 85%, 47% 90%, 100% 90%,
    100% 100%, 500% -500%, -500% -500%, 0 100%
  );
  background-image:
    radial-gradient(circle, black 50%, transparent 55%),
    radial-gradient(circle, black 20%, transparent 25%),
    radial-gradient(ellipse, black 10%, transparent 15%),
    radial-gradient(circle at 90% 70%, black 8%, transparent 12%),
    radial-gradient(ellipse, black 10%, transparent 15%),
    radial-gradient(circle at 60% 70%, black 8%, transparent 12%),
    radial-gradient(circle, black 40%, transparent 45%),
    radial-gradient(circle, black 40%, transparent 45%);
  background-size: 25vw 20vh, 50vw 30vh, 25vw 50vh, 25vw 20vh, 50vw 30vh, 25vw 50vh, 50vw 40vw, 10vw 20vh;
  background-position: 0 0,0 0,0 0,0 0,0 0,0 0, 10% 80%, 20% 20%;
}

body:hover {
  transform: none;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  z-index: 1;
  clip-path: none;
  animation: none;
  background: none;
}

body::after {
  content: "GAME OVER \a\a Move the mouse \a outside of the window \a to restart the game";
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #222e;
  font-family: Roboto, Arial, sans-serif;
  font-size: 7.5vmin;
  color: white;
  text-shadow: 3px 3px black;
  white-space: pre;
  box-sizing: border-box;
  padding: 10vmin;
  text-align: center;
}

body:hover::after {
  display: flex;
}
