#speedo {
  position: fixed;
  left: 50%;
  bottom: 0;
  display: none;
  transform: translateX(-50%);
  width: clamp(190px, 23.4vw, 300px);
  aspect-ratio: 2 / 1;
  z-index: 10;
  pointer-events: none;
  --speed: 0;
}
#speedo .bezel {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  clip-path: inset(0 0 50% 0);
  background: conic-gradient(from -40deg,
    #00E5FF, #0090A8 14%, #0090A8 30%, #00E5FF 48%,
    #00E5FF 64%, #7FF2FF 80%, #0090A8 92%, #00E5FF);
  box-shadow:
    inset 0 0 0 2px rgba(5, 13, 31, .85),
    inset 0 2px 4px rgba(127, 242, 255, .4),
    inset 0 -6px 12px rgba(0, 0, 0, .6),
    0 10px 24px rgba(0, 0, 0, .6),
    0 0 26px rgba(0, 229, 255, .3);
}
#speedo .dial {
  position: absolute;
  left: 7.3%;
  top: 7.3%;
  width: 85.4%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, var(--walnut), var(--deep) 80%);
  box-shadow: inset 0 6px 16px rgba(0, 0, 0, .75), inset 0 -3px 6px rgba(0, 229, 255, .14);
  clip-path: inset(0 0 50% 0);
}
#speedo .arc {
  position: absolute;
  left: 12%;
  top: 12%;
  width: 76%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(from 180deg,
    rgba(0, 229, 255, 0) 0deg,
    var(--gem-amethyst) 8deg,
    var(--brass-hi) 95deg,
    var(--gem-aqua) 180deg,
    transparent 180.1deg);
  -webkit-mask: radial-gradient(circle, transparent 41%, #000 42%, #000 47%, transparent 48%);
  mask: radial-gradient(circle, transparent 41%, #000 42%, #000 47%, transparent 48%);
  clip-path: inset(0 0 50% 0);
  opacity: .92;
  filter: drop-shadow(0 0 6px rgba(0, 229, 255, .45));
}
#speedo .ticks {
  position: absolute;
  left: 12%;
  top: 12%;
  width: 76%;
  aspect-ratio: 1;
}
#speedo .ticks i {
  position: absolute;
  left: 50%;
  top: 0;
  width: 2px;
  height: 6%;
  margin-left: -1px;
  background: rgba(127, 242, 255, .7);
  transform-origin: 50% 833%;
  border-radius: 1px;
}
#speedo .ticks i.maj { height: 8.5%; width: 3px; background: var(--brass-hi); }
#speedo .readout {
  position: absolute;
  left: 50%;
  bottom: 26%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 2;
}
#speedo .readout .num { font-family: var(--font-mono); font-weight: 500; font-size: clamp(20px, 2.4vw, 30px); line-height: .9; }
#speedo .readout .lbl { font-size: clamp(7px, .75vw, 9px); margin-top: 1px; }
#speedo .needle {
  position: absolute;
  left: 50%;
  bottom: 17.3%;
  width: 4px;
  height: 39.3%;
  margin-left: -2px;
  transform-origin: 50% 100%;
  transform: rotate(calc(-90deg + var(--speed) * 180deg));
  background: linear-gradient(180deg, var(--gold-hot), var(--gold) 80%);
  border-radius: 3px 3px 1px 1px;
  box-shadow: 0 0 8px rgba(255, 224, 0, .6);
  transition: transform .12s linear;
  z-index: 3;
}
#speedo .hub {
  position: absolute;
  left: 50%;
  bottom: 11.3%;
  width: 12%;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 42% 34%, #B3F6FF, var(--brass) 50%, var(--brass-lo) 92%);
  box-shadow:
    0 0 11px rgba(0, 229, 255, .55), 0 0 22px rgba(0, 229, 255, .28),
    inset 0 -3px 6px rgba(0, 60, 70, .6), inset 0 2px 4px rgba(127, 242, 255, .55);
  border: 2px solid rgba(5, 13, 31, .7);
  z-index: 4;
}

#boost-pip {
  position: fixed;
  right: max(clamp(10px, 2vw, 26px), env(safe-area-inset-right));
  bottom: max(clamp(10px, 2vw, 26px), env(safe-area-inset-bottom));
  z-index: 10;
  pointer-events: none;
  width: clamp(52px, 5.8vw, 74px);
  height: clamp(140px, 26vh, 208px);
  border-radius: 18px;
  padding: clamp(7px, .8vw, 10px);
  display: none;
  flex-direction: column;
  align-items: center;
  opacity: .55;
  background: conic-gradient(from -40deg,
    var(--coral), var(--coral-lo) 14%, var(--coral-hi) 30%, var(--coral) 48%,
    var(--coral-hi) 64%, var(--coral-hi) 80%, var(--coral-lo) 92%, var(--coral));
  box-shadow:
    inset 0 0 0 2px rgba(5, 13, 31, .85),
    inset 0 2px 4px rgba(var(--glow-coral), .4),
    inset 0 -6px 12px rgba(0, 0, 0, .6),
    0 10px 24px rgba(0, 0, 0, .6);
  transition: opacity .25s var(--zen-ease);
}
#boost-pip.shown { display: flex; }
#boost-pip .cap {
  width: 62%;
  height: clamp(9px, 1.9vh, 14px);
  margin-bottom: 7px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--coral-hi), var(--coral-lo));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 2px 4px rgba(0, 0, 0, .5);
}
#boost-pip .vial {
  position: relative;
  width: 52%;
  flex: 1;
  border-radius: 11px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(5, 13, 31, .92), rgba(14, 27, 51, .95));
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, .72), inset 0 0 0 1.5px rgba(var(--glow-coral), .25);
}
#boost-pip .vfill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 26%;
  background: linear-gradient(0deg, var(--coral-lo), var(--coral) 50%, var(--coral-hi) 92%);
  box-shadow: 0 0 18px rgba(var(--glow-coral), .65), 0 0 30px rgba(var(--glow-coral), .4);
  border-radius: 0 0 9px 9px;
  transition: height .3s var(--zen-ease);
}
#boost-pip .vfill::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 13px, rgba(5, 13, 31, .35) 13px 15px),
    linear-gradient(100deg, rgba(255, 255, 255, .5), transparent 42%);
}
#boost-pip .tag {
  margin-top: 8px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: .12em;
  color: var(--coral-hi);
  text-shadow: 0 0 10px rgba(var(--glow-coral), .7);
}
#boost-pip.on {
  opacity: 1;
  animation: boostReady 1.2s var(--zen-ease) infinite;
}
#boost-pip.on .vfill { height: 92%; }
@keyframes boostReady { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.22); } }

#hud .hud-map {
  position: absolute;
  left: max(var(--edge), env(safe-area-inset-left));
  bottom: max(var(--edge), env(safe-area-inset-bottom));
  width: clamp(150px, 16.5vw, 212px);
  aspect-ratio: 212 / 150;
  transform: rotate(-2.5deg);
}
.hud-map .sheet {
  position: absolute;
  inset: 9% 5%;
  border-radius: 8px;
  background: radial-gradient(120% 120% at 30% 20%, var(--walnut-hi), var(--walnut) 60%, var(--deep) 100%);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .55), inset 0 0 24px rgba(0, 229, 255, .12), inset 0 0 0 1px rgba(0, 229, 255, .18);
  backdrop-filter: blur(6px);
}
.hud-map .sheet::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background:
    radial-gradient(circle at 78% 74%, rgba(0, 229, 255, .22), transparent 30%),
    radial-gradient(circle at 18% 64%, rgba(0, 229, 255, .16), transparent 26%);
}
.hud-map .roll {
  position: absolute;
  top: 4%;
  bottom: 4%;
  width: 10.4%;
  border-radius: 11px;
  background: linear-gradient(90deg, var(--deep), var(--walnut-hi) 45%, var(--deep));
  box-shadow: inset 0 2px 3px rgba(127, 242, 255, .25), inset 0 -3px 5px rgba(0, 0, 0, .55), 0 4px 10px rgba(0, 0, 0, .5);
  z-index: 2;
}
.hud-map .roll-l { left: 0; }
.hud-map .roll-r { right: 0; }
.hud-map .roll::before,
.hud-map .roll::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass-lo));
}
.hud-map .roll::before { top: 6px; }
.hud-map .roll::after { bottom: 6px; }
.hud-map .map-label {
  position: absolute;
  left: 50%;
  top: 13%;
  transform: translateX(-50%);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: clamp(8px, .8vw, 10px);
  letter-spacing: .16em;
  color: var(--brass-hi);
  text-transform: uppercase;
  opacity: .85;
  white-space: nowrap;
  z-index: 1;
}
.hud-map svg {
  position: absolute;
  left: 11%;
  top: 22%;
  width: 78%;
  height: 66%;
  z-index: 1;
}
.hud-map .map-track {
  fill: none;
  stroke: var(--brass);
  stroke-width: 2.4;
  stroke-dasharray: 5 5;
  opacity: .8;
  filter: drop-shadow(0 0 3px rgba(0, 229, 255, .5));
}
.hud-map .map-pin { filter: drop-shadow(0 0 4px currentColor); }

#countdown {
  text-shadow:
    0 4px 0 rgba(0, 0, 0, .7),
    0 8px 0 rgba(0, 0, 0, .5),
    0 12px 0 rgba(0, 0, 0, .25),
    0 0 60px rgba(0, 229, 255, .5),
    0 0 120px rgba(0, 229, 255, .3);
}
#countdown::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(220px, 30vw, 380px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 229, 255, .28), rgba(0, 229, 255, .1) 45%, transparent 70%);
  filter: blur(6px);
  opacity: inherit;
  z-index: -1;
}

body.touch-mode #hud .hud-map { display: none; }
body.touch-mode #boost-pip {
  left: max(clamp(10px, 2vw, 26px), env(safe-area-inset-left));
  right: auto;
  bottom: clamp(150px, 46vh, 300px);
  height: clamp(96px, 20vh, 150px);
}

@media (orientation: landscape) and (max-height: 480px) {
  .standings { display: none; }
  #speedo { width: clamp(150px, 22vw, 190px); }
  #boost-pip { height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  .hud-gem, .hud-gem.focal::after, #boost-pip.on { animation: none !important; }
}

/* ── Play.fun safe-area bridge: when the game runs inside Play.fun's mobile frame,
   the SDK sets --ogp-safe-top/bottom-inset. Fold them into the in-race edge UI so
   nothing hides under the Play.fun header or Safari bars. 0px fallback = standalone. ── */
#hud .tl { top: max(var(--edge), env(safe-area-inset-top), var(--ogp-safe-top-inset, 0px)); }
#hud .tr { top: calc(max(var(--edge), env(safe-area-inset-top), var(--ogp-safe-top-inset, 0px)) + clamp(44px, 7.8vh, 56px)); }
#hud .standings { top: calc(max(var(--edge), env(safe-area-inset-top), var(--ogp-safe-top-inset, 0px)) + clamp(86px, 11vw, 140px)); }
#hud .hud-map { bottom: max(var(--edge), env(safe-area-inset-bottom), var(--ogp-safe-bottom-inset, 0px)); }
#speedo { bottom: var(--ogp-safe-bottom-inset, 0px); }
