:root {
  --fg: #f3f0e8;
  --muted: rgba(243, 240, 232, 0.55);
  --faint: rgba(243, 240, 232, 0.3);
  --line: rgba(243, 240, 232, 0.14);
  --glow: rgba(243, 240, 232, 0.42);
  --ember: #ff4a3d;
  --ease: cubic-bezier(0.22, 0.8, 0.2, 1);
  --font: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --display: "Unbounded", "Space Grotesk", ui-sans-serif, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game,
#trail {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#trail {
  z-index: 2;
  cursor: crosshair;
}

.flash {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255, 74, 61, 0.1), rgba(255, 30, 20, 0.55));
  opacity: 0;
  transition: opacity 0.5s ease;
}

.flash.on {
  opacity: 1;
  transition: none;
}

.slowmo {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(243, 240, 232, 0.14) 100%);
  box-shadow: inset 0 0 0 1px rgba(243, 240, 232, 0.2);
  transition: opacity 0.4s ease;
}

.slowmo.on {
  opacity: 1;
}

.pops {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.pop {
  position: absolute;
  font-family: var(--display);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: var(--fg);
  text-shadow: 0 0 14px var(--glow);
  transform: translate(-50%, -50%);
  animation: rise 0.9s var(--ease) forwards;
}

.pop.combo {
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  color: #fff;
  text-shadow: 0 0 30px #fff, 0 0 60px var(--glow);
  animation: combo 1.2s var(--ease) forwards;
}

.pop.bad {
  color: var(--ember);
  text-shadow: 0 0 20px var(--ember);
}

.hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud a,
.hud button {
  pointer-events: auto;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  height: 40px;
  padding: 0 14px 0 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(243, 240, 232, 0.035);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.back:hover {
  color: var(--fg);
}

.back svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.score b {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  line-height: 1;
  letter-spacing: 0.04em;
  text-shadow: 0 0 24px var(--glow);
  font-variant-numeric: tabular-nums;
}

.score b.bump {
  animation: bump 0.25s var(--ease);
}

.score > span {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: lowercase;
  color: var(--faint);
}

.score i {
  font-style: normal;
  color: var(--muted);
}

.hud-r {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: end;
}

.lives {
  display: flex;
  gap: 7px;
}

.lives i {
  width: 11px;
  height: 11px;
  border: 1px solid var(--fg);
  background: var(--fg);
  transform: rotate(45deg);
  box-shadow: 0 0 10px var(--glow);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, transform 0.4s var(--ease);
}

.lives i.off {
  background: transparent;
  border-color: var(--ember);
  box-shadow: none;
  transform: rotate(45deg) scale(0.8);
}

.mute {
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--muted);
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(243, 240, 232, 0.035);
  cursor: pointer;
}

.mute[aria-pressed="true"] {
  text-decoration: line-through;
  color: var(--faint);
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 90px 20px max(30px, env(safe-area-inset-bottom));
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.82));
  animation: fade 0.5s ease;
  touch-action: auto;
}

.screen[hidden] {
  display: none;
}

.kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--faint);
}

.logo {
  margin: 14px 0 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.4rem, 12vw, 6.6rem);
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 0 0 40px var(--glow);
}

.glitch {
  position: relative;
  display: inline-block;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}

.glitch::before {
  color: var(--ember);
  clip-path: inset(0 0 60% 0);
  animation: glitch-a 3.2s steps(1) infinite;
}

.glitch::after {
  color: #9ef;
  clip-path: inset(55% 0 0 0);
  animation: glitch-b 2.7s steps(1) infinite;
  opacity: 0.7;
}

.sub {
  margin: 16px 0 0;
  font-size: clamp(0.9rem, 2.4vw, 1.05rem);
  letter-spacing: 0.1em;
  color: var(--muted);
}

.legend {
  display: grid;
  gap: 10px;
  margin: 30px 0 0;
  padding: 16px 20px;
  list-style: none;
  text-align: left;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(243, 240, 232, 0.03);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 12px;
}

.legend i {
  flex: none;
  width: 14px;
  height: 14px;
}

.lg-bug {
  background: var(--ember);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  box-shadow: 0 0 10px var(--ember);
}

.lg-packet {
  border: 1.5px solid var(--fg);
}

.lg-core {
  border-radius: 50%;
  background: radial-gradient(circle, #fff, #ffd98a 60%, transparent 70%);
  box-shadow: 0 0 12px #ffd98a;
}

.lg-prod {
  border: 1.5px solid #7dffa8;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(125, 255, 168, 0.5) 3px 4px);
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 30px;
  padding: 18px 40px;
  overflow: hidden;
  font-family: var(--display);
  font-size: 0.95rem;
  letter-spacing: 0.26em;
  text-transform: lowercase;
  color: #000;
  background: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 2px;
  box-shadow: 0 0 40px rgba(243, 240, 232, 0.3);
  cursor: pointer;
  transition: transform 0.3s var(--ease), box-shadow 0.3s ease;
}

.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.9) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: sheen 3.2s var(--ease) infinite;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 0 70px rgba(243, 240, 232, 0.5);
  outline: none;
}

.btn.ghost {
  color: var(--fg);
  background: transparent;
  border-color: var(--line);
  box-shadow: none;
}

.btn.ghost::after {
  display: none;
}

.how {
  margin: 20px 0 0;
  max-width: 26rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.7;
  letter-spacing: 0.06em;
  color: var(--faint);
}

.big {
  margin: 10px 0 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(4rem, 20vw, 10rem);
  line-height: 1;
  text-shadow: 0 0 50px var(--glow);
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 12px;
}

.home {
  margin-top: 26px;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-decoration: none;
}

.home:hover {
  color: var(--fg);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  z-index: 20;
  padding: 8px 14px;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: var(--fg);
  background: rgba(10, 10, 12, 0.8);
  border: 1px solid var(--line);
  border-radius: 2px;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

@keyframes combo {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2) rotate(-6deg); filter: blur(8px); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-3deg); filter: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(0.95) rotate(-3deg); }
}

@keyframes bump {
  50% { transform: scale(1.18); }
}

@keyframes fade {
  from { opacity: 0; }
}

@keyframes sheen {
  0%, 55% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}

@keyframes glitch-a {
  0%, 86%, 100% { transform: none; }
  88% { transform: translate(-4px, 1px); }
  91% { transform: translate(3px, -1px); }
  94% { transform: translate(-2px, 0); }
}

@keyframes glitch-b {
  0%, 80%, 100% { transform: none; }
  83% { transform: translate(4px, 0); }
  86% { transform: translate(-3px, 1px); }
}

@media (max-width: 600px) {
  .back span {
    display: none;
  }

  .back {
    padding: 0 12px;
  }

  .legend {
    font-size: 0.72rem;
    padding: 14px 16px;
  }

  .screen {
    padding-top: 76px;
  }
}

@media (max-height: 640px) {
  .legend {
    margin-top: 18px;
    gap: 6px;
  }

  .btn {
    margin-top: 18px;
  }

  .how {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .glitch::before,
  .glitch::after,
  .btn::after {
    animation: none;
  }
}
