.fox-run {
  --fr-paper: #1d1840;
  --fr-ink: #fff6ec;
  --fr-muted: #ffdadd;
  --fr-mint: #dcffa9;
  --fr-ember: #ffa882;
  --fr-stroke: #a176aa;
  --fr-drift: 3.2s;
  display: grid;
  gap: .66rem;
  min-width: 0;
  padding: clamp(.65rem, 2.4vw, 1.22rem);
  border: 1px solid var(--fr-stroke);
  border-radius: 21px;
  background: linear-gradient(145deg, #32204b, var(--fr-paper) 75%);
  color: var(--fr-ink);
  box-shadow: 0 .3rem 0 #100c27;
}

.fox-run[data-tier='2'] { --fr-drift: 2.55s; --fr-ember: #f9b189; }
.fox-run[data-tier='3'] { --fr-drift: 1.85s; --fr-ember: #ffd27f; }
.fox-run [hidden] { display: none; }

.fr-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: .45rem .8rem;
}

.fr-heading h2 {
  margin: 0;
  color: inherit;
  font-size: clamp(1.19rem, 3.5vw, 1.9rem);
  line-height: 1.12;
}

.fr-heading p { margin: .28rem 0 0; color: var(--fr-muted); font-size: .97rem; line-height: 1.38; }
.fr-heading > span { color: var(--fr-mint); font-size: .85rem; font-weight: 800; }

.fr-hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: .4rem .3rem;
  border: 1px solid #916992;
  border-radius: 11px;
  background: #261938;
  text-align: center;
}

.fr-hud > div { display: grid; align-content: center; min-height: 2.35rem; }
.fr-hud > div + div { border-left: 1px solid #79567d; }
.fr-hud small { color: var(--fr-muted); font-weight: 700; font-size: .77rem; }
.fr-hud b { font-variant-numeric: tabular-nums; line-height: 1.27; font-size: clamp(1rem, 3.4vw, 1.25rem); }
.fr-score { color: var(--fr-mint); }

.fr-scene {
  --fr-ledge: 20%;
  --fr-runner: 13%;
  --fr-sprite: clamp(4.9rem, 18vw, 10.4rem);
  --fr-obstacle: clamp(1.9rem, 8vw, 4rem);
  position: relative;
  isolation: isolate;
  min-height: clamp(12.25rem, 42vw, 20rem);
  overflow: hidden;
  border: 1px solid #d396b0;
  border-radius: 14px;
  background: linear-gradient(160deg, #222255 9%, #542a5c 62%, #ac546e 100%);
}

.fr-landscape, .fr-stars { position: absolute; inset: 0; }

.fr-stars {
  opacity: .83;
  background-image:
    radial-gradient(2px 2px at 14px 17px, #ffe1bc 94%, transparent),
    radial-gradient(1.4px 1.4px at 69px 30px, #fff 94%, transparent),
    radial-gradient(1px 1px at 30px 58px, #ffd0cb 94%, transparent),
    radial-gradient(1px 1px at 97px 65px, #ffd7ad 94%, transparent);
  background-size: 118px 81px;
  mask-image: linear-gradient(#000 40%, transparent 78%);
}

.fr-moon {
  position: absolute;
  top: 11%;
  right: 10%;
  width: clamp(4rem, 16vw, 8rem);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(ellipse at 70% 56%, #e08a89 5% 12%, transparent 13%),
    radial-gradient(ellipse at 44% 35%, #ffd4a2 9%, transparent 11%),
    repeating-linear-gradient(165deg, #ffc38d 0 7%, #f6aa89 8% 12%, #ffd5a1 13% 18%);
  box-shadow: 0 0 32px #ff997567;
}

.fr-ridge {
  position: absolute;
  right: 0;
  left: 0;
  bottom: calc(var(--fr-ledge) - 6%);
  height: 43%;
  clip-path: polygon(0 59%, 8% 54%, 13% 25%, 18% 32%, 21% 25%, 25% 70%, 32% 78%, 38% 52%, 43% 50%, 49% 9%, 54% 25%, 62% 63%, 67% 47%, 76% 47%, 81% 30%, 86% 44%, 89% 40%, 94% 65%, 100% 55%, 100% 100%, 0 100%);
}

.fr-ridge-far { background: #74496d; transform: translateY(-14%) scaleX(1.3); }
.fr-ridge-near { background: #493251; transform: scaleX(-1); }

.fr-track {
  position: absolute;
  inset: auto 0 0;
  height: var(--fr-ledge);
  border-top: 3px solid var(--fr-ember);
  box-shadow: inset 0 .25rem #703d61, 0 -.18rem 0 #281750;
  background:
    repeating-linear-gradient(116deg, transparent 0 24px, #81506d 25px 27px, transparent 28px 48px) 0 .55rem / 48px 1.3rem repeat-x,
    linear-gradient(180deg, #402745, #281e36 84%);
}

.fr-portal {
  position: absolute;
  right: 5%;
  bottom: var(--fr-ledge);
  width: clamp(2.8rem, 11vw, 5.2rem);
  height: clamp(3.55rem, 14vw, 6.2rem);
  border: .27rem solid #deff9b;
  border-radius: 48% 48% 10% 10%;
  opacity: .2;
  background: repeating-linear-gradient(9deg, #c3f88755 0 6%, #5e9b4977 6% 15%);
  box-shadow: 0 0 1.1rem #cdff9d, inset 0 0 1rem #b5ef82;
  transition: opacity .3s, transform .3s;
  transform: scale(.8);
}

.fox-run[data-tier='3'] .fr-portal { opacity: .77; transform: scale(1); }
.fox-run[data-phase='finished'][data-tier='3'] .fr-portal { opacity: 1; }

.fr-fox {
  position: absolute;
  left: var(--fr-runner);
  bottom: calc(var(--fr-ledge) - .19rem);
  width: var(--fr-sprite);
  z-index: 2;
  transform-origin: center bottom;
  filter: drop-shadow(0 .25rem 0 #1c163b8c);
}

.fr-fox img { display: block; width: 100%; height: auto; }

.fr-rock {
  position: absolute;
  left: calc(var(--fr-runner) + var(--fr-sprite) + clamp(.45rem, 5vw, 4.2rem));
  bottom: var(--fr-ledge);
  width: var(--fr-obstacle);
  height: calc(var(--fr-obstacle) * .79);
  background: linear-gradient(152deg, #ffae86 12%, #a8587c 24% 48%, #684063 50% 67%, #ba6f75 69%);
  clip-path: polygon(0 100%, 9% 46%, 37% 36%, 50% 1%, 71% 19%, 85% 46%, 100% 63%, 94% 100%);
}

.fr-rock i { position: absolute; inset: 44% 21% 14% 47%; background: #e09887; clip-path: polygon(30% 0, 100% 35%, 79% 76%, 11% 100%, 0 48%); }
.fr-rock i + i { inset: 29% 53% 57% 26%; background: #fcd0a2; }

.fr-sparks {
  position: absolute;
  z-index: 3;
  left: calc(var(--fr-runner) + var(--fr-sprite));
  bottom: calc(var(--fr-ledge) + var(--fr-obstacle) * .65);
  opacity: 0;
  color: var(--fr-mint);
}

.fr-sparks i {
  position: absolute;
  width: .37rem;
  aspect-ratio: 1;
  background: currentColor;
  box-shadow: 0 0 .55rem currentColor;
  transform: translate(var(--fr-x, 0), var(--fr-y, 0)) rotate(45deg);
}

.fr-sparks i:nth-child(2) { --fr-x: .6rem; --fr-y: -.7rem; }
.fr-sparks i:nth-child(3) { --fr-x: 1.15rem; --fr-y: .5rem; }
.fr-sparks i:nth-child(4) { --fr-x: -.8rem; --fr-y: -.5rem; width: .23rem; }
.fr-sparks i:nth-child(5) { --fr-x: 1.3rem; --fr-y: -1.26rem; width: .24rem; }

.fr-prompt {
  position: absolute;
  z-index: 5;
  top: .65rem;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 1rem);
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  padding: .35rem min(5vw, 1.35rem) .45rem;
  border: 1px solid #ab8aab;
  border-radius: 13px;
  background: #211737f4;
  color: #fff9ed;
  box-shadow: 0 .16rem 0 #321a4785;
  text-align: center;
}

.fr-direction { font-size: .77rem; color: var(--fr-mint); font-weight: 750; }
.fr-target { min-width: 0; overflow-wrap: anywhere; font-size: clamp(1.2rem, 4vw, 2.12rem); line-height: 1.1; }

.fr-progress { display: flex; align-items: center; gap: .55rem; color: var(--fr-muted); font-size: .85rem; font-weight: 750; }
.fr-route { flex: 1; height: .51rem; min-width: 0; overflow: hidden; background: #593758; color: var(--fr-mint); border: 0; border-radius: 40px; accent-color: var(--fr-mint); }
.fr-route::-webkit-progress-bar { background: #593758; }
.fr-route::-webkit-progress-value { background: var(--fr-mint); }
.fr-route::-moz-progress-bar { background: var(--fr-mint); }

.fr-controls, .fr-entry { display: flex; flex-wrap: wrap; gap: .45rem; }
.fr-button {
  min-height: 44px;
  padding: .45rem .75rem;
  border: 1px solid #be94ae;
  border-radius: 9px;
  background: #422a4f;
  color: var(--fr-ink);
  cursor: pointer;
  font: inherit;
  font-size: .9rem;
  font-weight: 750;
  text-align: center;
}

.fr-button:hover { background: #57365d; }
.fr-main-button { background: var(--fr-mint); border-color: #e6ffd0; color: #201832; }
.fr-main-button:hover { background: #f0ffc8; }
.fox-run[data-input='turn'] [data-fr='voice'] { background: #422a4f; border-color: #be94ae; color: var(--fr-ink); }
.fox-run[data-input='turn'] [data-fr='turn'] { background: var(--fr-mint); border-color: #e6ffd0; color: #201832; }
.fr-button:focus-visible, .fr-entry input:focus-visible { outline: 2px solid #fff3c3; outline-offset: 3px; }
.fr-entry label { flex: 1; min-width: min(100%, 8rem); }
.fr-entry input { box-sizing: border-box; width: 100%; min-height: 44px; padding: .46rem .62rem; border: 1px solid #c7a9c0; border-radius: 8px; background: #fcf4ff; color: #271b40; font: inherit; }
.fr-status { min-height: 1.3rem; margin: 0; font-size: .94rem; line-height: 1.35; }
.fr-note { margin: -.28rem 0 0; color: var(--fr-muted); font-size: .79rem; }
.fr-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; clip-path: inset(50%); overflow: hidden; }

.fox-run[data-phase='running'] .fr-track { animation: fr-ground var(--fr-drift) linear infinite; }
.fox-run[data-phase='running'] .fr-stars { animation: fr-stars 45s linear infinite; }
.fox-run[data-phase='running'] .fr-fox { animation: fr-pace .68s ease-in-out infinite; }
.fox-run .is-jumping .fr-fox { animation: fr-jump .47s ease-in-out; }
.fox-run .is-jumping .fr-rock { animation: fr-cross .47s ease-in-out; }
.fox-run .is-jumping .fr-sparks { animation: fr-flash .47s ease-out; }

@keyframes fr-ground { to { background-position: -192px .55rem, 0 0; } }
@keyframes fr-stars { to { background-position: -118px 0; } }
@keyframes fr-pace { 50% { transform: translateY(-.16rem) rotate(-1.3deg); } }
@keyframes fr-jump {
  25% { transform: translate(12%, -45%) rotate(-6deg); }
  59% { transform: translate(25%, -52%) rotate(4deg); }
  88% { transform: translate(4%, -5%) rotate(1deg); }
}
@keyframes fr-cross {
  49% { transform: translateX(calc(-1 * var(--fr-sprite) - var(--fr-obstacle))); opacity: 1; }
  50% { transform: translateX(calc(-1 * var(--fr-sprite) - var(--fr-obstacle))); opacity: 0; }
  51% { transform: translateX(calc(var(--fr-sprite) * 1.8)); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}
@keyframes fr-flash {
  12% { opacity: 1; transform: scale(.72); }
  60% { opacity: .72; transform: translate(.2rem, -.65rem) scale(1.2); }
  100% { opacity: 0; transform: translate(.4rem, -1rem) scale(1.32); }
}

@media (max-width: 420px) {
  .fr-scene { --fr-runner: 9%; }
  .fr-controls .fr-button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .fox-run .fr-track, .fox-run .fr-stars, .fox-run .fr-fox, .fox-run .fr-rock, .fox-run .fr-sparks { animation: none !important; }
  .fox-run .fr-portal { transition: none; }
}
