:root {
  --text: #eef0ff;
  --muted: #8f97cc;
  --size: min(94vw, calc(100vh - 270px), 580px);
  --size: min(94vw, calc(100dvh - 270px), 580px);
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  background: #05071a;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.sky {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% -10%, #1d2766 0%, #0a0f2c 55%, #04061a 100%);
}
.sky i {
  position: absolute;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .28;
  animation: drift 26s ease-in-out infinite alternate;
}
.sky i:nth-child(1) { background: #ff3d7f; left: -25vmax; top: -15vmax; }
.sky i:nth-child(2) { background: #22c7ff; right: -30vmax; top: 25vh; animation-duration: 33s; }
.sky i:nth-child(3) { background: #8b5cff; left: 5vw; bottom: -40vmax; animation-duration: 40s; }
@keyframes drift { to { transform: translate(9vmax, -7vmax) scale(1.15); } }

.app {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.title {
  font-size: clamp(26px, 7vw, 38px);
  font-weight: 900;
  letter-spacing: .02em;
  line-height: 1;
  display: flex;
}
.title span {
  color: var(--col);
  text-shadow: 0 0 18px color-mix(in srgb, var(--col) 60%, transparent), 0 3px 0 rgba(0, 0, 0, .35);
  animation: hop 3.2s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 90ms);
}
.title span:nth-child(1) { --i: 0; } .title span:nth-child(2) { --i: 1; }
.title span:nth-child(3) { --i: 2; } .title span:nth-child(4) { --i: 3; }
.title span:nth-child(5) { --i: 4; } .title span:nth-child(6) { --i: 5; }
.title span:nth-child(7) { --i: 6; } .title span:nth-child(8) { --i: 7; }
@keyframes hop { 0%, 80%, 100% { transform: none; } 88% { transform: translateY(-5px); } }

.top {
  width: var(--size);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.stat, .next {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat.right { align-items: flex-end; text-align: right; }
.next { align-items: center; }
.label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.value {
  font-size: clamp(24px, 6.5vw, 32px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.value.bump { animation: bump .45s ease-out; }
@keyframes bump { 30% { transform: scale(1.25); color: #fff6b0; } }

.next-balls {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.next-balls .orb {
  position: relative;
  inset: auto;
  width: 22px;
  height: 22px;
  animation: pop-in .35s cubic-bezier(.3, 1.6, .5, 1) both;
}

.board {
  width: var(--size);
  height: var(--size);
  padding: calc(var(--size) * .018);
  border-radius: calc(var(--size) * .045);
  background: linear-gradient(160deg, rgba(255, 255, 255, .11), rgba(255, 255, 255, .03));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .1),
    0 30px 60px -20px rgba(0, 0, 0, .7),
    0 0 80px -30px rgba(120, 140, 255, .5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.board.shake { animation: shake .3s; }
@keyframes shake {
  20% { transform: translateX(-5px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(2px); }
}

.field { position: relative; width: 100%; height: 100%; }
.cells, .balls, .fx { position: absolute; inset: 0; }
.balls, .fx { pointer-events: none; }
.fx { overflow: visible; }

.cells { display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); }
.cell { position: relative; cursor: pointer; }
.cell::before {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 24%;
  background: rgba(8, 12, 40, .45);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .45), inset 0 -1px 0 rgba(255, 255, 255, .06);
  transition: background .15s;
}
@media (hover: hover) {
  .cell:hover::before { background: rgba(255, 255, 255, .08); }
}
.cell.path::after {
  content: "";
  position: absolute;
  inset: 42%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
  box-shadow: 0 0 8px rgba(255, 255, 255, .6);
}
.cell.nope::before { animation: nope .4s; }
@keyframes nope { 30% { background: rgba(255, 60, 90, .45); } }

.ball {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / 9);
  height: calc(100% / 9);
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
}
.ball.moving { transition: transform var(--step, 50ms) linear; z-index: 2; }
.ball::before {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 9%;
  height: 12%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  filter: blur(2px);
}
.ball.ghost::before { display: none; }

.orb {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, .95) 0 6%, transparent 22%),
    radial-gradient(circle at 36% 32%, var(--hi) 0%, var(--col) 42%, var(--deep) 96%);
  box-shadow:
    inset 0 -3px 7px rgba(0, 0, 0, .35),
    inset 0 2px 2px rgba(255, 255, 255, .25),
    0 0 16px -3px var(--col);
}
.orb::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 7%;
  height: 22%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, var(--hi), transparent 70%);
  opacity: .35;
}
.k0 { --col: #ff4d6d; --hi: #ffb3c1; --deep: #7a0c25; }
.k1 { --col: #ff8a3d; --hi: #ffd6b5; --deep: #8a3505; }
.k2 { --col: #ffd23f; --hi: #fff4c2; --deep: #946600; }
.k3 { --col: #36d97f; --hi: #c4ffdd; --deep: #075c30; }
.k4 { --col: #2fd3ff; --hi: #c9f4ff; --deep: #005a7d; }
.k5 { --col: #4f6dff; --hi: #c8d3ff; --deep: #16247d; }
.k6 { --col: #b85cff; --hi: #ead1ff; --deep: #4e1590; }

.ball.spawn .orb { animation: pop-in .38s cubic-bezier(.3, 1.6, .5, 1) both; }
.ball.ghost .orb { inset: 36%; opacity: .55; animation: pop-in .3s ease-out both; }
.ball.selected { z-index: 1; }
.ball.selected .orb { animation: bounce .55s ease-in-out infinite; box-shadow: inset 0 -3px 7px rgba(0, 0, 0, .35), 0 0 22px 2px var(--col); }
.ball.selected::before { animation: shadow .55s ease-in-out infinite; }
.ball.gone .orb { animation: vanish .35s ease-in forwards; }
.ball.gone::before { opacity: 0; transition: opacity .2s; }

@keyframes pop-in { from { transform: scale(0); } 70% { transform: scale(1.12); } to { transform: scale(1); } }
@keyframes bounce {
  0%, 100% { transform: translateY(5%) scale(1.06, .93); }
  50% { transform: translateY(-16%) scale(.97, 1.03); }
}
@keyframes shadow { 50% { transform: scale(.7); opacity: .5; } }
@keyframes vanish { 40% { transform: scale(1.25); filter: brightness(1.8); } to { transform: scale(.2); opacity: 0; filter: brightness(2.5); } }

.spark {
  position: absolute;
  width: 2%;
  height: 2%;
  margin: -1% 0 0 -1%;
  border-radius: 50%;
  background: var(--col);
  box-shadow: 0 0 8px 1px var(--col);
  animation: fly .7s cubic-bezier(.15, .7, .3, 1) forwards;
}
@keyframes fly { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
.ring {
  position: absolute;
  width: calc(100% / 9);
  height: calc(100% / 9);
  margin: calc(-100% / 18) 0 0 calc(-100% / 18);
  border-radius: 50%;
  border: 2px solid var(--col);
  box-shadow: 0 0 12px var(--col);
  animation: ring .5s ease-out forwards;
}
@keyframes ring { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.gain {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: calc(var(--size) * .07);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 14px rgba(255, 230, 120, .9), 0 3px 0 rgba(0, 0, 0, .4);
  animation: rise 1s ease-out forwards;
  white-space: nowrap;
}
@keyframes rise {
  from { transform: translate(-50%, -20%) scale(.5); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  to { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

.bottom { display: flex; gap: 10px; }
.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  padding: 12px 22px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12), 0 6px 16px -8px rgba(0, 0, 0, .6);
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.95); }
@media (hover: hover) { .btn:hover { background: rgba(255, 255, 255, .14); } }
.btn.icon { padding: 10px 13px; display: grid; place-items: center; }
.btn.icon svg { width: 22px; height: 22px; }
.btn.icon .mute { display: none; }
.btn.icon.off .mute { display: inline; }
.btn.icon.off .wave { display: none; }
.btn.primary {
  background: linear-gradient(135deg, #ff4d6d, #b85cff);
  box-shadow: 0 10px 24px -8px rgba(184, 92, 255, .8);
  padding: 14px 28px;
  font-size: 17px;
}

.hint {
  max-width: var(--size);
  text-align: center;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--muted);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 5, 20, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade .35s ease-out;
  z-index: 10;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.card {
  text-align: center;
  padding: 30px 34px;
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(40, 48, 110, .95), rgba(16, 20, 54, .95));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12), 0 30px 80px -20px #000;
  animation: pop-in .45s cubic-bezier(.3, 1.5, .5, 1);
}
.card h2 { font-size: 22px; font-weight: 800; color: var(--muted); }
.final { font-size: 64px; font-weight: 900; line-height: 1.1; margin: 6px 0 2px; text-shadow: 0 0 30px rgba(184, 92, 255, .7); }
.record { min-height: 1.4em; margin-bottom: 18px; font-weight: 700; color: #ffd23f; }

@media (max-height: 560px) {
  :root { --size: min(94vw, calc(100dvh - 150px), 580px); }
  .title, .hint { display: none; }
}
