:root {
  --red: #ff3b30;
  --amber: #ffce3d;
  --green: #2dd36f;
  --off: #10131b;
  --cycle: 14.58s;
  --sky-top: #8cc8ff;
  --sky-bottom: #cfe7ff;
  --grass: #7fbf6d;
  --road: #3b3b3b;
  --road-line: #f2d85b;
  --house: #f3e1c7;
  --house-edge: #d3c1a6;
  --roof: #b65442;
  --window-frame: #7a5a3d;
  --car-start-x: calc(100vw + 160px);
  --car-stop-x: 18vw;
  --car-delay: 6s;
  --car-drive: 4.5s;
  --final-sky-top: #ffe08a;
  --final-sky-bottom: #ffb36d;
  --final-floor: #88c36a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e9e9e9;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.scene {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: 3fr 1fr;
  background: #fff;
  overflow: hidden;
}

.final-scene {
  position: fixed;
  inset: 0;
  display: none;
  overflow: hidden;
  z-index: 200;
}

body.show-final .scene {
  display: none;
}

body.show-final .final-scene {
  display: block;
}

.final-stage {
  position: relative;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.35), transparent 45%),
    linear-gradient(180deg, var(--final-sky-top), var(--final-sky-bottom) 65%, var(--final-floor) 65%);
}

.final-car {
  position: absolute;
  left: 9vw;
  bottom: 17vh;
  width: clamp(180px, 19vw, 320px);
  height: auto;
  image-rendering: pixelated;
}

.final-target {
  position: absolute;
  right: 14vw;
  bottom: 22vh;
  width: clamp(130px, 16vw, 260px);
  height: auto;
  border: 6px solid #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.tomato-splat {
  position: absolute;
  right: 16.5vw;
  bottom: 23.5vh;
  width: clamp(90px, 10vw, 150px);
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at 35% 35%, #ff8d7f 0, #ff5544 35%, #d62121 70%, #8f1010 100%);
  border-radius: 42% 58% 55% 45% / 46% 38% 62% 54%;
  opacity: 0;
  transform: scale(0.2) rotate(-18deg);
  filter: drop-shadow(0 4px 8px rgba(130, 0, 0, 0.4));
  pointer-events: none;
}

.tomato-splat::before,
.tomato-splat::after {
  content: "";
  position: absolute;
  background: #d62121;
  border-radius: 50%;
}

.tomato-splat::before {
  width: 34%;
  height: 34%;
  left: -14%;
  top: 44%;
}

.tomato-splat::after {
  width: 28%;
  height: 28%;
  right: -10%;
  top: 18%;
}

.toy-shot {
  position: absolute;
  left: 23vw;
  bottom: 30vh;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fffbe0, #ffe24f 65%, #ff9800 100%);
  opacity: 0;
  box-shadow: 0 0 10px rgba(255, 208, 0, 0.8);
}

.pew-text,
.impact-text {
  position: absolute;
  font-weight: 800;
  font-size: clamp(28px, 5vw, 64px);
  letter-spacing: 0.06em;
  color: #111;
  opacity: 0;
  transform: scale(0.6);
  text-shadow: 2px 2px 0 #fff;
}

.pew-text {
  left: 26vw;
  bottom: 36vh;
}

.impact-text {
  right: 17vw;
  bottom: 39vh;
}

.final-scene.play .final-car {
  animation: finalCarHop 0.42s ease-in-out 0.4s 2;
}

.final-scene.play .toy-shot {
  animation: toyShotFly 1.05s linear 0.7s forwards;
}

.final-scene.play .pew-text {
  animation: popLabel 0.5s ease-out 0.68s forwards;
}

.final-scene.play .impact-text {
  animation: popLabel 0.6s ease-out 1.6s forwards;
}

.final-scene.play .tomato-splat {
  animation: tomatoSplash 1.2s ease-out 1.55s forwards;
}

.final-scene.play .final-target {
  animation:
    targetHitShake 0.3s linear 1.55s 3,
    targetFallAway 1.8s ease-in 2.45s forwards;
}

.sky {
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 40px 48px 28px;
  gap: 40px;
}

.ground {
  background: var(--grass);
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  padding: 0;
}

.road {
  width: 100%;
  height: 96px;
  background: var(--road);
  border-radius: 0;
  position: relative;
  overflow: visible;
}

.lane {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  transform: translateY(-50%);
  background: repeating-linear-gradient(
    90deg,
    var(--road-line) 0 34px,
    transparent 34px 68px
  );
}

.car {
  position: absolute;
  bottom: 10px;
  left: var(--car-start-x);
  width: 120px;
  height: auto;
  animation: carArrive var(--car-drive) linear var(--car-delay) 1 forwards;
  transform: scaleX(-1);
  transform-origin: center;
  image-rendering: pixelated;
  z-index: 2;
}

.car.escape {
  animation: carEscape 3.2s ease-in forwards;
}

.house {
  width: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.roof {
  width: 0;
  height: 0;
  border-left: 130px solid transparent;
  border-right: 130px solid transparent;
  border-bottom: 92px solid var(--roof);
}

.wall {
  width: 260px;
  height: 180px;
  background: var(--house);
  border: 4px solid var(--house-edge);
  display: flex;
  align-items: center;
  justify-content: center;
}

.window {
  width: 170px;
  height: 120px;
  background: #9ed1ff;
  border: 6px solid var(--window-frame);
  position: relative;
  overflow: visible;
}

.window-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transform-origin: center;
}

.window-image--a {
  opacity: 1;
  animation: windowSwapOut 0s linear forwards;
  animation-delay: 8s;
}

.window-image--b {
  animation: windowSwapIn 0s linear forwards;
  animation-delay: 8s;
}

.window-image--b.runaway {
  animation: windowRunAway 3.2s cubic-bezier(0.2, 0.7, 0.25, 1) forwards;
  z-index: 30;
}

.ampel {
  background: #000;
  padding: 18px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.light {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background-color: var(--off);
}

.light.red {
  animation: redCycle var(--cycle) infinite;
}

.light.yellow {
  animation: yellowCycle var(--cycle) infinite;
}

.light.green {
  animation: greenCycle var(--cycle) infinite;
}

@keyframes redCycle {
  0%,
  41.152% {
    background-color: var(--red);
  }
  41.153%,
  100% {
    background-color: var(--off);
  }
}

@keyframes yellowCycle {
  0%,
  28.807% {
    background-color: var(--off);
  }
  28.808%,
  41.152% {
    background-color: var(--amber);
  }
  41.153%,
  86.283% {
    background-color: var(--off);
  }
  86.284%,
  100% {
    background-color: var(--amber);
  }
}

@keyframes greenCycle {
  0%,
  41.152% {
    background-color: var(--off);
  }
  41.153%,
  76.818% {
    background-color: var(--green);
  }
  76.819%,
  78.395% {
    background-color: var(--off);
  }
  78.396%,
  79.973% {
    background-color: var(--green);
  }
  79.974%,
  81.550% {
    background-color: var(--off);
  }
  81.551%,
  83.128% {
    background-color: var(--green);
  }
  83.129%,
  84.705% {
    background-color: var(--off);
  }
  84.706%,
  86.283% {
    background-color: var(--green);
  }
  86.284%,
  100% {
    background-color: var(--off);
  }
}

@keyframes windowSwapOut {
  to {
    opacity: 0;
  }
}

@keyframes windowSwapIn {
  to {
    opacity: 1;
  }
}

@keyframes windowRunAway {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(-95vw, -45vh) rotate(-16deg) scale(0.82);
    opacity: 0;
  }
}

@keyframes carArrive {
  from {
    left: var(--car-start-x);
  }
  to {
    left: var(--car-stop-x);
  }
}

@keyframes carEscape {
  from {
    transform: translateX(0) scaleX(-1);
  }
  to {
    transform: translateX(-130vw) scaleX(-1);
  }
}

@keyframes finalCarHop {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes toyShotFly {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
  10% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translate(50vw, -7vh) scale(1);
  }
}

@keyframes popLabel {
  0% {
    opacity: 0;
    transform: scale(0.6) rotate(-8deg);
  }
  30% {
    opacity: 1;
    transform: scale(1.15) rotate(4deg);
  }
  100% {
    opacity: 0;
    transform: scale(1) rotate(0deg);
  }
}

@keyframes tomatoSplash {
  0% {
    opacity: 0;
    transform: scale(0.2) rotate(-18deg);
  }
  28% {
    opacity: 0.95;
    transform: scale(1.1) rotate(-8deg);
  }
  100% {
    opacity: 0.7;
    transform: scale(1) rotate(-2deg);
  }
}

@keyframes targetHitShake {
  0% {
    transform: translateX(0) rotate(0deg);
  }
  25% {
    transform: translateX(-8px) rotate(-2deg);
  }
  50% {
    transform: translateX(8px) rotate(2deg);
  }
  75% {
    transform: translateX(-6px) rotate(-1deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
  }
}

@keyframes targetFallAway {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-48vw, 30vh) rotate(-55deg) scale(0.55);
  }
}
