:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --gold: #ffd84a;
  --mint: #4ff0b4;
  --hud-h: 52px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 10px;
  background:
    radial-gradient(120% 70% at 50% 0%, #1d1b44 0%, rgba(15, 16, 32, 0) 60%),
    var(--bg);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
button,
input {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: #2f3048;
  box-shadow: 0 2px 0 #0a0b16;
  font: inherit;
  font-size: 0.85em;
  color: #e6e7f5;
}

.shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* HUD */
.hud {
  width: 100%;
  min-height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.brand-icon {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 3px 6px rgba(104, 66, 255, 0.5));
}
.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #efe9ff, #b9a5ff 55%, #8a6bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chips {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  padding: 8px 13px;
  border-radius: 999px;
  background: linear-gradient(180deg, #26273b, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0a0b16;
}
.chip span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip strong {
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.chip-mass strong {
  color: var(--mint);
}
.chip-rank strong {
  color: #b9a5ff;
}
.chip-best strong {
  color: var(--gold);
}
.chip.pop strong {
  display: inline-block;
  animation: pop 0.3s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes pop {
  50% {
    transform: scale(1.3);
  }
}

/* Pills */
.pill {
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s,
    filter 0.12s;
}
.pill:active {
  transform: translateY(2px);
}
.pill:disabled {
  opacity: 0.45;
  cursor: default;
}
.pill-primary {
  background: linear-gradient(180deg, #8a6bff, var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 4px 0 #3d22b3,
    0 10px 24px rgba(104, 66, 255, 0.45);
}
.pill-primary:hover {
  filter: brightness(1.08);
}
.pill-secondary {
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #13141f;
}
.pill-big {
  min-height: 56px;
  min-width: 180px;
  font-size: 22px;
}
.icon-pill {
  flex: 0 0 auto;
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}
.icon-pill svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Stage */
.stage {
  position: relative;
  width: 100%;
  height: clamp(300px, calc(100svh - 20px - var(--hud-h) - 8px), 680px);
  border-radius: 22px;
  overflow: hidden;
  background: #14152a;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.06),
    0 18px 40px rgba(0, 0, 0, 0.45);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  outline: none;
}
.stage canvas:focus-visible {
  box-shadow: inset 0 0 0 3px var(--gold);
}
.stage.shake {
  animation: shake 0.45s;
}
@keyframes shake {
  20% {
    transform: translate(-6px, 2px);
  }
  40% {
    transform: translate(5px, -3px);
  }
  60% {
    transform: translate(-3px, 2px);
  }
  80% {
    transform: translate(2px, -1px);
  }
}

/* Leaderboard */
.board {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 224px;
  padding: 10px 12px 8px;
  border-radius: 16px;
  background: rgba(21, 22, 38, 0.78);
  backdrop-filter: blur(6px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 6px 18px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  font-size: 13px;
}
.board h2 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  text-align: center;
}
.board ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}
.board li,
.board-me {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 2px 6px;
  border-radius: 8px;
  color: #dcdef0;
}
.board li .pos {
  width: 16px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.board li .nm {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board li .ms {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.bot-tag {
  flex: 0 0 auto;
  padding: 0 4px;
  border-radius: 5px;
  background: #33354f;
  color: #aeb1d6;
  font-size: 9px;
  letter-spacing: 0.06em;
  line-height: 15px;
}
.board li.me,
.board-me {
  background: linear-gradient(
    90deg,
    rgba(104, 66, 255, 0.55),
    rgba(104, 66, 255, 0.15)
  );
  color: #fff;
}
.board-me {
  margin: 4px 0 0;
}
.board-me[hidden] {
  display: none;
}

/* Action buttons */
.actions {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}
.act {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  touch-action: manipulation;
  transition: transform 0.1s;
}
.act svg {
  width: 26px;
  height: 26px;
  fill: #fff;
}
.act span {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.act kbd {
  margin-top: 1px;
  padding: 0 4px;
  font-size: 9px;
  background: rgba(0, 0, 0, 0.25);
  box-shadow: none;
}
.act:active {
  transform: scale(0.92);
}
.act:disabled {
  opacity: 0.4;
  cursor: default;
}
.act-split {
  width: 84px;
  height: 84px;
  background: radial-gradient(circle at 35% 28%, #b7a4ff, #6842ff 55%, #4520cf);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.2),
    0 6px 0 #2d178f,
    0 12px 26px rgba(104, 66, 255, 0.5);
}
.act-eject {
  width: 64px;
  height: 64px;
  background: radial-gradient(circle at 35% 28%, #9ff7d6, #1fc68d 55%, #0f8f64);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.2),
    0 5px 0 #0a6246,
    0 10px 22px rgba(31, 198, 141, 0.4);
}
.act-eject svg {
  width: 22px;
  height: 22px;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(
    circle at 50% 45%,
    rgba(20, 16, 50, 0.55),
    rgba(8, 8, 20, 0.82)
  );
  overflow-y: auto;
}
.overlay[hidden] {
  display: none;
}
.card {
  width: min(400px, 100%);
  padding: 22px 22px 18px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, #262740, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 8px 0 #0b0c18,
    0 24px 60px rgba(0, 0, 0, 0.55);
  animation: card-in 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes card-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
.card-kicker {
  margin: 0;
  color: var(--mint);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.card-title {
  margin: 2px 0 6px;
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.05;
  background: linear-gradient(180deg, #fff, #c9b8ff 50%, #8a6bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #2d178f);
}
.card-copy {
  margin: 0 auto 14px;
  max-width: 330px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}
.final {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}
.final[hidden] {
  display: none;
}
.final-stat {
  display: grid;
  gap: 2px;
  padding: 10px 4px;
  border-radius: 16px;
  background: #15162a;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.3);
}
.final-stat span {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.final-stat strong {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.final-stat:first-child strong {
  color: var(--mint);
}
.badge {
  grid-column: 1 / -1;
  order: -1;
  justify-self: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe680, #ffb020);
  color: #3b2400;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 3px 0 #b36b00;
  animation: pop 0.5s cubic-bezier(0.3, 1.8, 0.5, 1) both;
}
.badge[hidden] {
  display: none;
}
.name-field {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  margin: 0 auto 14px;
  padding: 4px 4px 4px 14px;
  border-radius: 999px;
  background: #15162a;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.3);
}
.name-field span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.name-field input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: #22233a;
  font-weight: 900;
  font-size: 16px;
}
.name-field input::placeholder {
  color: #6f7290;
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.card-actions [hidden] {
  display: none;
}
.card-keys {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.8;
}

@media (hover: none) and (pointer: coarse) {
  .act kbd,
  .card-keys {
    display: none;
  }
}

@media (max-width: 640px) {
  .brand h1 {
    display: none;
  }
  .chip {
    padding: 7px 10px;
    gap: 4px;
  }
  .chip span {
    font-size: 10px;
  }
  .chip strong {
    font-size: 16px;
  }
  .board {
    width: 178px;
    top: 8px;
    right: 8px;
    padding: 7px 8px 6px;
    font-size: 11px;
  }
  .board h2 {
    font-size: 11px;
    margin-bottom: 4px;
  }
  .board li:nth-child(n + 6) {
    display: none;
  }
  .board li .ms {
    font-size: 10px;
  }
  .board li,
  .board-me {
    gap: 4px;
    padding: 2px 4px;
  }
  .bot-tag {
    font-size: 8px;
    padding: 0 3px;
  }
  .card-title {
    font-size: 34px;
  }
  .act-split {
    width: 76px;
    height: 76px;
  }
  .act-eject {
    width: 58px;
    height: 58px;
  }
}
@media (max-width: 360px) {
  .chip span {
    display: none;
  }
  .chips {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
