.gas {
  --boost-fill: 34%;
  background: linear-gradient(
    to bottom,
    #ff5a5f 0 34%,
    var(--lime) 34% 100%
  );
}

.gas::after {
  opacity: 0.9;
}

.brake-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.drift {
  width: clamp(66px, 10vw, 96px);
  height: clamp(54px, 8vw, 78px);
  border-radius: 999px;
  background: var(--cyan);
  font-size: clamp(0.62rem, 1.6vw, 0.86rem);
}

.drift.is-down {
  background: var(--yellow);
  transform: translate(3px, 3px) rotate(-3deg);
}

.boost-hud {
  --boost-charge: 100%;
  position: absolute;
  left: 50%;
  bottom: clamp(92px, 20vh, 150px);
  width: clamp(116px, 18vw, 178px);
  transform: translateX(-50%) rotate(-1deg);
  color: var(--ink);
  text-align: center;
  transition: transform 120ms ease;
}

.boost-hud > span {
  display: inline-block;
  margin-bottom: 4px;
  padding: 2px 8px 3px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: clamp(0.48rem, 1.2vw, 0.68rem);
  letter-spacing: 0.08em;
}

.boost-hud > div {
  position: relative;
  height: 15px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: rgb(255 248 232 / 0.82);
  box-shadow: 3px 3px 0 var(--ink);
}

.boost-hud i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--boost-charge);
  background: linear-gradient(90deg, #ff922b, #ff5a5f);
  transition: width 70ms linear;
}

.boost-hud.is-boosting {
  transform: translateX(-50%) scale(1.08) rotate(1deg);
}

.boost-hud.is-boosting > div {
  box-shadow:
    3px 3px 0 var(--ink),
    0 0 0 5px rgb(255 90 95 / 0.28);
}

.boost-hud.is-drift-charging i {
  background: linear-gradient(90deg, #38d9ff, #8ce99a);
}

.boost-hud.is-boost-full-flash {
  animation: turn-boost-full-flash 520ms cubic-bezier(.16,.82,.24,1);
}

.boost-hud.is-boost-full-flash > div {
  animation: turn-boost-full-bar-flash 520ms ease-out;
}

.boost-hud.is-boost-empty-flash {
  animation: turn-boost-empty-flash 620ms cubic-bezier(.28,.78,.34,1);
}

.boost-hud.is-boost-empty-flash > div {
  animation: turn-boost-empty-bar-flash 620ms ease-out;
}

@keyframes turn-boost-full-flash {
  0%, 100% { transform: translateX(-50%) rotate(-1deg) scale(1); }
  24% { transform: translateX(-50%) rotate(2deg) scale(1.2); }
  52% { transform: translateX(-50%) rotate(-2deg) scale(1.08); }
  76% { transform: translateX(-50%) rotate(1deg) scale(1.14); }
}

@keyframes turn-boost-full-bar-flash {
  0%, 100% {
    background: rgb(255 248 232 / 0.82);
    box-shadow: 3px 3px 0 var(--ink);
  }
  28%, 72% {
    background: #fff6a8;
    box-shadow:
      3px 3px 0 var(--ink),
      0 0 0 7px rgb(56 217 255 / 0.5),
      0 0 22px 10px rgb(255 212 59 / 0.58);
  }
  48% {
    background: #ffffff;
  }
}

@keyframes turn-boost-empty-flash {
  0%, 100% { transform: translateX(-50%) rotate(-1deg); }
  14% { transform: translateX(calc(-50% - 7px)) rotate(-5deg); }
  28% { transform: translateX(calc(-50% + 7px)) rotate(4deg); }
  42% { transform: translateX(calc(-50% - 5px)) rotate(-4deg); }
  56% { transform: translateX(calc(-50% + 4px)) rotate(3deg); }
  72% { transform: translateX(calc(-50% - 2px)) rotate(-2deg); }
}

@keyframes turn-boost-empty-bar-flash {
  0%, 100% {
    background: rgb(255 248 232 / 0.82);
    box-shadow: 3px 3px 0 var(--ink);
  }
  18%, 54% {
    background: #ff5a5f;
    box-shadow:
      3px 3px 0 var(--ink),
      0 0 0 6px rgb(255 90 95 / 0.48);
  }
  36%, 72% {
    background: #fff8e8;
  }
}

@media (prefers-reduced-motion: reduce) {
  .boost-hud.is-boost-full-flash,
  .boost-hud.is-boost-empty-flash {
    animation: none;
  }
}

.race-position-hud {
  position: absolute;
  left: 38%;
  bottom: clamp(112px, 25vh, 190px);
  min-width: 82px;
  padding: 6px 10px 8px;
  border: 3px solid var(--ink);
  border-radius: 15px;
  background: rgb(255 248 232 / 0.94);
  color: var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  text-align: center;
  transform: rotate(-3deg);
  transform-origin: center;
}

.race-position-hud span {
  display: block;
  font-size: 0.5rem;
  letter-spacing: 0.08em;
}

.race-position-hud strong {
  display: block;
  margin-top: 1px;
  font-size: clamp(1.15rem, 3vw, 1.75rem);
  line-height: 1;
}

.race-position-hud.position-pop {
  animation: turn-position-pop 420ms cubic-bezier(.15,.85,.2,1);
}

@keyframes turn-position-pop {
  0% { transform: rotate(-3deg) scale(1); }
  35% { transform: rotate(4deg) scale(1.42); background: var(--yellow); }
  65% { transform: rotate(-5deg) scale(1.18); }
  100% { transform: rotate(-3deg) scale(1); }
}

@media (max-height: 430px) {
  .brake-stack {
    gap: 6px;
  }

  .drift {
    width: 64px;
    height: 48px;
  }

  .boost-hud {
    bottom: 74px;
    width: 112px;
  }

  .race-position-hud {
    left: 40%;
    bottom: 92px;
    min-width: 72px;
    padding: 5px 8px 6px;
  }
}
