:root {
  color-scheme: light;
  --ink: #142033;
  --paper: #fff9e8;
  --blue: #066bdf;
  --red: #ff7a00;
  --grass: #67b866;
  --asphalt: #5b6168;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #f7d36a;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.game-shell {
  position: relative;
  width: min(100vw, 1280px);
  height: min(100vh, 720px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #9bd8ff;
  box-shadow: 0 18px 45px rgba(28, 23, 9, 0.28);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.hud {
  position: absolute;
  inset: 16px 16px auto 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  pointer-events: none;
  color: #10151d;
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
}

.hud > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

#levelName {
  font-size: clamp(15px, 2.1vw, 25px);
  white-space: nowrap;
}

#levelCount,
.hud-stat {
  font-size: clamp(12px, 1.4vw, 15px);
  padding: 4px 8px;
  border: 2px solid rgba(20, 32, 51, 0.78);
  background: rgba(255, 255, 255, 0.52);
}

.hud-stat {
  white-space: nowrap;
}

.icon-button {
  pointer-events: auto;
  display: grid;
  place-items: center;
  min-width: 42px;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border: 3px solid #142033;
  background: rgba(255, 249, 232, 0.82);
  color: #142033;
  font: 900 24px/1 Arial, Helvetica, sans-serif;
  box-shadow: 3px 3px 0 #142033;
  text-shadow: none;
}

.icon-button.is-muted {
  color: #fff;
  background: #5b6168;
}

.meter {
  width: clamp(96px, 16vw, 180px);
  height: 12px;
  border: 2px solid #142033;
  background: rgba(255, 255, 255, 0.6);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #35b56a, #ffcf48, #ff6b35);
}

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(255, 249, 232, 0.76);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.message.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.message h1 {
  margin: 0;
  font-size: clamp(44px, 10vw, 118px);
  line-height: 0.9;
  color: #e94820;
  text-shadow: 4px 4px 0 #142033, 7px 7px 0 #ffd24f;
}

.message p {
  max-width: 540px;
  margin: 0 auto;
  font-size: clamp(16px, 2vw, 23px);
  font-weight: 700;
}

.stats-table {
  justify-self: center;
  min-width: min(520px, 90vw);
  border: 4px solid #142033;
  background: #fff9e8;
  box-shadow: 5px 5px 0 #142033;
  overflow: hidden;
}

.stats-table[hidden] {
  display: none;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 12px 16px;
  font-weight: 900;
  font-size: clamp(16px, 2vw, 24px);
}

.stats-row + .stats-row {
  border-top: 3px solid #142033;
}

.stats-row span:first-child {
  text-align: left;
}

.stats-row span:last-child {
  color: #e94820;
}

.message-actions,
.level-select {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.level-select {
  max-width: min(720px, 92vw);
}

.level-select[hidden],
.scene-art:empty {
  display: none;
}

.level-select button {
  min-width: 118px;
  min-height: 40px;
  background: #fff9e8;
  color: #142033;
  font-size: 14px;
}

.scene-art {
  position: relative;
  justify-self: center;
  width: min(680px, 90vw);
  height: clamp(150px, 26vw, 230px);
}

.scene-ground {
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: 7%;
  height: 18px;
  background: #64ad5d;
  border: 3px solid #142033;
}

.scene-dan,
.scene-dad,
.scene-friend {
  position: absolute;
  bottom: 12%;
  width: 112px;
  height: 152px;
  transform-origin: 50% 85%;
}

.scene-dan {
  left: 12%;
  animation: sceneWiggle 0.7s ease-in-out infinite alternate;
}

.scene-dad {
  right: 12%;
  width: 124px;
  height: 164px;
  animation: dadTalk 0.9s ease-in-out infinite alternate;
}

.scene-friend {
  animation: partyBounce 0.55s ease-in-out infinite alternate;
}

.scene-friend:nth-child(3) {
  left: 8%;
  animation-delay: 0.1s;
}

.scene-friend:nth-child(4) {
  left: 30%;
  animation-delay: 0.24s;
}

.scene-friend:nth-child(5) {
  right: 30%;
  animation-delay: 0.16s;
}

.scene-friend:nth-child(6) {
  right: 8%;
  animation-delay: 0.34s;
}

.scene-bike {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 0;
  height: 48px;
  border-bottom: 8px solid #066bdf;
}

.scene-bike::before,
.scene-bike::after {
  content: "";
  position: absolute;
  bottom: -18px;
  width: 36px;
  height: 36px;
  border: 7px solid #142033;
  border-radius: 50%;
  background: #fff9e8;
}

.scene-bike::before {
  left: 0;
}

.scene-bike::after {
  right: 0;
}

.scene-body {
  position: absolute;
  left: 44px;
  bottom: 54px;
  width: 34px;
  height: 54px;
  background: #066bdf;
  border: 4px solid #142033;
  transform: rotate(-8deg);
}

.scene-head {
  position: absolute;
  left: 34px;
  bottom: 112px;
  width: 52px;
  height: 52px;
  border: 4px solid #142033;
  border-radius: 50%;
  background: #ffd3ad;
}

.scene-head::before {
  content: "";
  position: absolute;
  left: -7px;
  top: -9px;
  width: 60px;
  height: 28px;
  border-radius: 50% 50% 35% 35%;
  background: #ff7a00;
}

.scene-dad .scene-head::before {
  left: -3px;
  top: -5px;
  width: 54px;
  height: 22px;
  border-radius: 46% 46% 30% 30%;
  background: transparent;
  border-left: 10px solid #7d3f1b;
  border-right: 10px solid #7d3f1b;
  border-top: 6px solid #7d3f1b;
}

.scene-dad .scene-head::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 31px;
  width: 32px;
  height: 10px;
  border-radius: 999px;
  background: #4b2617;
}

.scene-dad .scene-head {
  left: 38px;
  bottom: 122px;
  background:
    radial-gradient(circle at 52% 17%, #ffe0bd 0 16px, transparent 17px),
    #ffd3ad;
}

.scene-dad .scene-body {
  left: 48px;
  bottom: 62px;
  background: #e94820;
}

.scene-dad .scene-bike {
  border-bottom-color: #e94820;
}

.scene-training-wheel {
  position: absolute;
  bottom: -16px;
  width: 20px;
  height: 20px;
  border: 5px solid #142033;
  border-radius: 50%;
  background: #fff9e8;
  animation: trainingWheelDrop 1.3s ease-in-out infinite;
}

.scene-training-wheel-left {
  left: 2px;
}

.scene-training-wheel-right {
  right: 2px;
  animation-delay: 0.18s;
}

.scene-banner {
  position: absolute;
  left: 50%;
  top: 0;
  width: min(560px, 84vw);
  padding: 10px 12px;
  border: 4px solid #142033;
  background: #ffcf48;
  color: #142033;
  font: 900 clamp(18px, 3vw, 32px)/1 Arial, Helvetica, sans-serif;
  transform: translateX(-50%) rotate(-2deg);
}

.scene-confetti {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 12% 26%, #e94820 0 5px, transparent 6px),
    radial-gradient(circle at 28% 10%, #066bdf 0 5px, transparent 6px),
    radial-gradient(circle at 44% 22%, #ffcf48 0 5px, transparent 6px),
    radial-gradient(circle at 70% 14%, #67b866 0 5px, transparent 6px),
    radial-gradient(circle at 86% 28%, #e94820 0 5px, transparent 6px);
  animation: confettiDrift 0.9s linear infinite alternate;
}

button {
  justify-self: center;
  min-width: 150px;
  min-height: 44px;
  border: 3px solid #142033;
  background: #066bdf;
  color: #fff;
  font: 800 17px/1 Arial, Helvetica, sans-serif;
  box-shadow: 4px 4px 0 #142033;
  cursor: pointer;
}

button:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #142033;
}

@keyframes sceneWiggle {
  from { transform: rotate(-2deg) translateY(0); }
  to { transform: rotate(2deg) translateY(-4px); }
}

@keyframes dadTalk {
  from { transform: rotate(1deg); }
  to { transform: rotate(-1deg) translateY(-2px); }
}

@keyframes partyBounce {
  from { transform: translateY(0) rotate(-3deg); }
  to { transform: translateY(-14px) rotate(4deg); }
}

@keyframes confettiDrift {
  from { transform: translateY(0); }
  to { transform: translateY(10px); }
}

@keyframes trainingWheelDrop {
  0%, 32% {
    opacity: 1;
    transform: translate(0, 0) rotate(0);
  }
  68%, 100% {
    opacity: 0.2;
    transform: translate(var(--wheel-fall-x, -26px), 44px) rotate(-160deg);
  }
}

.scene-training-wheel-right {
  --wheel-fall-x: 26px;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .game-shell {
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
  }

  .hud {
    inset: 10px 10px auto 10px;
  }

  #levelName {
    max-width: 58vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hud {
    align-items: flex-start;
  }

  .hud > div:first-child {
    flex-wrap: wrap;
    max-width: 72vw;
  }
}
