:root {
  --navy-950: #07091a;
  --navy-900: #0c1029;
  --navy-800: #15183b;
  --purple-900: #24105a;
  --purple-700: #5b25c7;
  --purple-500: #8e4cff;
  --lavender-200: #eadcff;
  --lavender-100: #f4ecff;
  --yellow-500: #ffea19;
  --yellow-600: #ffd21f;
  --white: #fffdf5;
  --panel-border: #9a62ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 50% 12%, rgba(142, 76, 255, 0.22), transparent 38rem),
    linear-gradient(180deg, #090b20 0%, #050613 100%);
  color: var(--white);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
}

.game-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(8px, 1.8vw, 24px);
}

.game-frame {
  position: relative;
  width: min(100%, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  border: 4px solid #2b176c;
  background: var(--navy-950);
  box-shadow:
    0 0 0 2px rgba(255, 234, 25, 0.25),
    0 26px 80px rgba(0, 0, 0, 0.56);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.fullscreen-control {
  position: absolute;
  top: 14px;
  right: 14px;
  width: clamp(38px, 4.6vw, 58px);
  aspect-ratio: 1;
  border: 3px solid var(--panel-border);
  background:
    linear-gradient(180deg, rgba(25, 18, 58, 0.96), rgba(12, 16, 41, 0.98));
  box-shadow:
    inset 0 0 0 2px #050718,
    0 5px 0 #2a155f,
    0 0 18px rgba(142, 76, 255, 0.42);
  cursor: pointer;
  z-index: 5;
  transition: transform 140ms ease, filter 140ms ease;
  animation: hudIdleGlow 2.8s steps(6, end) infinite;
}

.fullscreen-control:hover {
  filter: brightness(1.16);
  transform: translateY(-2px);
}

.fullscreen-control span {
  position: absolute;
  inset: 10px;
  content: "";
  background:
    linear-gradient(var(--white), var(--white)) left top / 13px 3px no-repeat,
    linear-gradient(var(--white), var(--white)) left top / 3px 13px no-repeat,
    linear-gradient(var(--white), var(--white)) right top / 13px 3px no-repeat,
    linear-gradient(var(--white), var(--white)) right top / 3px 13px no-repeat,
    linear-gradient(var(--white), var(--white)) left bottom / 13px 3px no-repeat,
    linear-gradient(var(--white), var(--white)) left bottom / 3px 13px no-repeat,
    linear-gradient(var(--white), var(--white)) right bottom / 13px 3px no-repeat,
    linear-gradient(var(--white), var(--white)) right bottom / 3px 13px no-repeat;
}

.jump-control {
  position: absolute;
  right: clamp(14px, 4vw, 30px);
  bottom: clamp(18px, 5vw, 42px);
  display: none;
  width: 86px;
  aspect-ratio: 1;
  border: 4px solid var(--yellow-500);
  border-radius: 50%;
  background:
    radial-gradient(circle at 40% 30%, rgba(255, 244, 142, 0.95), var(--yellow-500) 36%, var(--purple-700) 38%, var(--purple-900) 100%);
  color: var(--white);
  font-size: 14px;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow:
    inset 0 -8px 0 rgba(7, 9, 26, 0.34),
    0 8px 0 #150735,
    0 0 26px rgba(255, 234, 25, 0.28);
  cursor: pointer;
  z-index: 3;
  animation: ctaPulse 1.9s steps(6, end) infinite;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 56px);
  background:
    linear-gradient(180deg, rgba(7, 9, 26, 0.42), rgba(7, 9, 26, 0.58)),
    rgba(10, 7, 28, 0.28);
  backdrop-filter: blur(4px);
  z-index: 4;
  animation: overlayFade 260ms steps(5, end) both;
}

.overlay.hidden {
  display: none;
}

.start-panel {
  width: min(760px, 88vw);
  text-align: center;
  padding: clamp(18px, 3.4vw, 36px);
  border: 4px solid var(--panel-border);
  background:
    linear-gradient(180deg, rgba(12, 16, 41, 0.94), rgba(20, 12, 54, 0.94));
  box-shadow:
    inset 0 0 0 3px #050718,
    0 9px 0 #311275,
    0 0 48px rgba(142, 76, 255, 0.36);
  animation: panelPop 340ms steps(7, end) both;
}

.start-panel.compact {
  width: min(520px, 88vw);
}

.start-panel.compact h2 {
  font-size: clamp(48px, 6vw, 72px);
}

.leaderboard-panel {
  width: min(760px, 92vw);
  max-height: 92%;
  padding: clamp(14px, 2.1vw, 22px);
  overflow: hidden;
}

.leaderboard-panel h2 {
  font-size: clamp(38px, 5.2vw, 58px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--purple-500);
  font-size: clamp(11px, 1.8vw, 14px);
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--yellow-500);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(48px, 8vw, 96px);
  line-height: 0.94;
  letter-spacing: 0;
  text-shadow:
    0 4px 0 #321671,
    4px 0 0 #090b20,
    -4px 0 0 #090b20,
    0 -4px 0 #090b20,
    0 0 20px rgba(255, 234, 25, 0.24);
}

h1 span {
  color: var(--white);
}

h1 {
  position: relative;
  overflow: hidden;
}

h1::after {
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: -28%;
  width: 18%;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.42), transparent);
  transform: skewX(-18deg);
  animation: titleGlint 3.2s steps(18, end) infinite;
}

h2 {
  color: var(--white);
}

.intro {
  max-width: 620px;
  margin: 18px auto 0;
  color: #f4ecff;
  font-size: clamp(14px, 2vw, 17px);
  font-weight: 750;
  line-height: 1.55;
}

.control-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.control-row span {
  min-width: 56px;
  padding: 8px 12px;
  border: 3px solid var(--panel-border);
  background: #15123b;
  color: var(--white);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: inset 0 -3px 0 #07091a;
  animation: keyFloat 1.8s steps(4, end) infinite;
}

.control-row span:nth-child(2) {
  animation-delay: 120ms;
}

.control-row span:nth-child(3) {
  animation-delay: 240ms;
}

.control-row span:nth-child(4) {
  animation-delay: 360ms;
}

.action-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.primary-button,
.secondary-button {
  min-width: min(220px, 100%);
  min-height: 56px;
  padding: 14px 24px;
  border: 0;
  color: #0b0d23;
  cursor: pointer;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow:
    inset 0 -5px 0 rgba(29, 11, 83, 0.52),
    0 6px 0 #5d24c7;
}

.primary-button {
  background: var(--yellow-500);
  animation: ctaPulse 1.9s steps(6, end) infinite;
}

.secondary-button {
  color: var(--white);
  border: 3px solid var(--panel-border);
  background: rgba(36, 16, 90, 0.94);
}

.start-actions .primary-button {
  min-width: min(300px, 100%);
}

.primary-button:hover,
.secondary-button:hover {
  filter: brightness(1.08);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 -3px 0 rgba(29, 11, 83, 0.52),
    0 2px 0 #5d24c7;
}

.microcopy {
  margin: 20px 0 0;
  color: #d9c8ff;
  font-size: clamp(12px, 1.7vw, 14px);
  font-weight: 800;
}

.distance-copy {
  margin-top: 8px;
  color: var(--yellow-200);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.result-mascot {
  position: relative;
  width: min(320px, 78vw);
  height: 178px;
  margin: 4px auto 0;
}

.result-mascot img {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(310px, 100%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transform: translateX(-50%);
  animation: resultCatFloat 2.2s steps(7, end) infinite;
}

.result-mascot::before {
  display: none;
}

.leaderboard-table {
  width: min(620px, 100%);
  margin: 12px auto 0;
  border: 3px solid var(--panel-border);
  background: rgba(7, 9, 26, 0.72);
  box-shadow: inset 0 0 0 3px #050718;
  overflow: hidden;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 96px;
  gap: 12px;
  align-items: center;
  min-height: 24px;
  padding: 3px 12px;
  color: var(--lavender-100);
  font-size: clamp(12px, 1.8vw, 15px);
  font-weight: 850;
  text-transform: uppercase;
  border-bottom: 2px solid rgba(154, 98, 255, 0.22);
}

.leaderboard-panel .action-row {
  margin-top: 12px;
}

.leaderboard-panel .microcopy {
  margin-top: 10px;
}

.leaderboard-panel .primary-button,
.leaderboard-panel .secondary-button {
  min-height: 46px;
  padding: 10px 20px;
}

.leaderboard-row:last-child {
  border-bottom: 0;
}

.leaderboard-row.header {
  color: var(--yellow-500);
  background: rgba(91, 37, 199, 0.32);
  font-size: clamp(11px, 1.6vw, 13px);
}

.leaderboard-row.current {
  color: var(--white);
  background: rgba(255, 234, 25, 0.12);
  box-shadow: inset 4px 0 0 var(--yellow-500);
}

.leaderboard-row span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.leaderboard-row span:last-child {
  color: var(--yellow-500);
  text-align: right;
}

.orientation-lock {
  display: none;
}

.orientation-lock__content {
  width: min(420px, calc(100vw - 48px));
  text-align: center;
}

.orientation-lock h2 {
  margin: 26px 0 0;
  color: var(--yellow-500);
  font-family: inherit;
  font-size: clamp(34px, 10vw, 48px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0.06em;
  text-shadow: none;
}

.orientation-lock p {
  margin: 22px auto 0;
  color: #cfc4f5;
  font-size: clamp(19px, 5.2vw, 26px);
  font-weight: 650;
  line-height: 1.25;
}

.rotate-phone-icon {
  display: block;
  width: 146px;
  height: 112px;
  margin: 0 auto;
}

@keyframes overlayFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes panelPop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  70% {
    opacity: 1;
    transform: translateY(-2px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes titleGlint {
  0%,
  58% {
    left: -28%;
  }
  82%,
  100% {
    left: 112%;
  }
}

@keyframes keyFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

@keyframes ctaPulse {
  0%,
  100% {
    box-shadow:
      inset 0 -5px 0 rgba(29, 11, 83, 0.52),
      0 6px 0 #5d24c7,
      0 0 0 rgba(255, 234, 25, 0);
  }
  50% {
    box-shadow:
      inset 0 -5px 0 rgba(29, 11, 83, 0.52),
      0 6px 0 #5d24c7,
      0 0 22px rgba(255, 234, 25, 0.34);
  }
}

@keyframes hudIdleGlow {
  0%,
  100% {
    box-shadow:
      inset 0 0 0 2px #050718,
      0 5px 0 #2a155f,
      0 0 18px rgba(142, 76, 255, 0.42);
  }
  50% {
    box-shadow:
      inset 0 0 0 2px #050718,
      0 5px 0 #2a155f,
      0 0 26px rgba(255, 234, 25, 0.2);
  }
}

@keyframes resultCatFloat {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) rotate(0deg);
  }
  35% {
    transform: translateX(-50%) translateY(-5px) rotate(-1deg);
  }
  68% {
    transform: translateX(-50%) translateY(-2px) rotate(1deg);
  }
}

@keyframes resultShadowPulse {
  0%,
  100% {
    transform: scaleX(1);
    opacity: 0.72;
  }
  40% {
    transform: scaleX(0.72);
    opacity: 0.46;
  }
}

@media (max-width: 700px) {
  .game-shell {
    padding: 0;
  }

  .game-frame {
    width: 100vw;
    border-width: 0;
  }

  .start-panel {
    width: min(94vw, 760px);
  }

  .primary-button,
  .secondary-button {
    min-width: 160px;
  }

  .jump-control {
    display: block;
  }
}

@media (pointer: coarse) {
  .jump-control {
    display: block;
  }
}

@media (orientation: landscape) and (max-height: 430px) and (max-width: 900px) {
  .game-shell {
    padding: 0;
  }

  .game-frame {
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100dvh, calc(100vw * 9 / 16));
    border-width: 0;
  }

  .fullscreen-control {
    top: 10px;
    right: 10px;
    width: 42px;
    border-width: 2px;
  }

  .fullscreen-control span {
    inset: 9px;
  }

  .overlay {
    padding: 10px 54px 10px 12px;
    backdrop-filter: blur(3px);
  }

  .start-panel {
    width: min(560px, calc(100vw - 96px));
    max-height: calc(100dvh - 20px);
    padding: 13px 18px;
    border-width: 3px;
    box-shadow:
      inset 0 0 0 2px #050718,
      0 5px 0 #311275,
      0 0 34px rgba(142, 76, 255, 0.34);
    overflow: hidden;
  }

  .eyebrow {
    margin-bottom: 5px;
    font-size: 10px;
  }

  h1 {
    font-size: clamp(42px, 14vh, 56px);
  }

  .intro {
    max-width: 520px;
    margin-top: 10px;
    font-size: clamp(11px, 3.1vh, 13px);
    line-height: 1.34;
  }

  .control-row {
    gap: 6px;
    margin-top: 12px;
  }

  .control-row span {
    min-width: 48px;
    padding: 5px 9px;
    border-width: 2px;
    font-size: 10px;
  }

  .action-row {
    gap: 8px;
    margin-top: 14px;
  }

  .primary-button,
  .secondary-button {
    min-width: 180px;
    min-height: 40px;
    padding: 9px 16px;
    font-size: 14px;
    box-shadow:
      inset 0 -4px 0 rgba(29, 11, 83, 0.52),
      0 4px 0 #5d24c7;
  }

  .start-actions .primary-button {
    min-width: 250px;
  }

  .start-panel.compact {
    width: min(460px, calc(100vw - 106px));
    padding: 10px 14px;
  }

  .start-panel.compact h2 {
    font-size: clamp(40px, 14vh, 52px);
  }

  .start-panel.compact #finalDistance {
    font-size: clamp(34px, 11.2vh, 42px);
    line-height: 0.9;
    white-space: nowrap;
  }

  .distance-copy {
    margin-top: 1px;
  }

  .result-mascot {
    width: min(250px, 76vw);
    height: 112px;
    margin-top: -2px;
  }

  .result-mascot img {
    width: min(232px, 100%);
  }

  .microcopy {
    margin-top: 7px;
    font-size: 11px;
  }

  .start-panel.compact .action-row {
    margin-top: 8px;
  }

  .start-panel.compact .primary-button,
  .start-panel.compact .secondary-button {
    min-height: 36px;
    padding: 7px 14px;
    font-size: 13px;
  }

  .leaderboard-panel {
    width: min(590px, calc(100vw - 92px));
    max-height: calc(100dvh - 18px);
    padding: 8px 10px;
  }

  .leaderboard-panel h2 {
    font-size: clamp(28px, 10vh, 36px);
    line-height: 0.92;
  }

  .leaderboard-table {
    width: 100%;
    margin-top: 6px;
    border-width: 2px;
    box-shadow: inset 0 0 0 2px #050718;
  }

  .leaderboard-row {
    grid-template-columns: 48px minmax(0, 1fr) 78px;
    gap: 8px;
    min-height: 18px;
    padding: 1px 8px;
    font-size: clamp(9px, 3vh, 12px);
    border-bottom-width: 1px;
  }

  .leaderboard-row.header {
    font-size: 10px;
  }

  .leaderboard-panel .microcopy {
    margin-top: 6px;
    font-size: 10px;
  }

  .leaderboard-panel .action-row {
    margin-top: 6px;
  }

  .leaderboard-panel .primary-button {
    min-width: 176px;
    min-height: 34px;
    padding: 7px 14px;
    font-size: 13px;
  }
}

@media (orientation: portrait) and (max-width: 820px) {
  body {
    overflow: hidden;
    background: #151827;
  }

  .game-shell {
    display: none;
  }

  .orientation-lock {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding:
      max(48px, env(safe-area-inset-top))
      24px
      max(40px, env(safe-area-inset-bottom));
    background: #151827;
  }
}
