:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6dff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --gold: #ffcf33;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 8px;
}
button {
  font: inherit;
  color: inherit;
}
.sa-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sa-shell {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* HUD */
.sa-hud {
  width: 100%;
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.sa-chip {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #27283c, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.09),
    0 4px 10px rgba(0, 0, 0, 0.25);
  line-height: 1.05;
}
.sa-chip > span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.sa-chip strong {
  font-size: 18px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.sa-chip strong b {
  font-weight: 900;
}
.sa-chip.is-bump strong {
  animation: sa-bump 0.35s ease-out;
}
@keyframes sa-bump {
  40% {
    transform: scale(1.3);
    color: var(--gold);
  }
}
.sa-coin {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c2, #ffcf33 45%, #d18a00);
  box-shadow:
    inset 0 -1px 0 rgba(0, 0, 0, 0.25),
    0 1px 2px rgba(0, 0, 0, 0.4);
  vertical-align: -2px;
}
.sa-icon-button {
  flex: 0 0 44px;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 10px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.sa-icon-button svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}
.sa-icon-button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Stage */
.sa-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100svh - 96px);
  min-height: 300px;
  border-radius: 20px;
  overflow: hidden;
  background: #7cc6ff;
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.45),
    inset 0 0 0 2px rgba(255, 255, 255, 0.06);
}
@media (max-width: 600px) {
  .sa-stage {
    aspect-ratio: 4 / 5;
    max-height: none;
  }
}
#sa-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  outline: none;
}
#sa-canvas:focus-visible {
  box-shadow: inset 0 0 0 3px #b9a8ff;
}

/* Overlays */
.sa-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: radial-gradient(
    ellipse at center,
    rgba(15, 16, 32, 0.55),
    rgba(15, 16, 32, 0.82)
  );
  overflow-y: auto;
  animation: sa-fade 0.25s ease-out;
}
.sa-overlay[hidden] {
  display: none;
}
@keyframes sa-fade {
  from {
    opacity: 0;
  }
}
.sa-card {
  width: min(360px, 100%);
  padding: 18px 18px 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, #25263a, var(--panel));
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  text-align: center;
  animation: sa-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.sa-card-wide {
  width: min(560px, 100%);
}
@keyframes sa-pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
.sa-logo {
  width: 110px;
  height: 82px;
  margin: -4px auto 0;
  display: block;
  animation: sa-float 2.4s ease-in-out infinite;
}
@keyframes sa-float {
  50% {
    transform: translateY(-5px) rotate(-2deg);
  }
}
.sa-title {
  margin: 2px 0 4px;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff 30%, #c9bcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #3b1fb3);
}
.sa-title-small {
  font-size: 26px;
}
.sa-lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-weight: 700;
  font-size: 15px;
}
.sa-kicker {
  margin: 0;
  color: var(--gold);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sa-meta {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.sa-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.sa-row {
  display: flex;
  gap: 8px;
}
.sa-row > * {
  flex: 1;
}
.sa-button {
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #34354b, var(--secondary));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 0 #17182a,
    0 8px 14px rgba(0, 0, 0, 0.3);
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.12s ease;
}
.sa-button:hover {
  filter: brightness(1.12);
}
.sa-button:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 1px 0 #17182a;
}
.sa-button-primary {
  background: linear-gradient(180deg, #8a6dff, var(--accent));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 0 #3b1fb3,
    0 10px 18px rgba(104, 66, 255, 0.4);
}
.sa-button-primary:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 0 #3b1fb3;
}
.sa-button-big {
  min-height: 54px;
  font-size: 21px;
}
.sa-button:focus-visible,
.sa-icon-button:focus-visible,
.sa-up:focus-visible,
.sa-hat:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}
.sa-big-score {
  margin: 4px 0 0;
  font-size: 46px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 3px 0 #9a5d00;
  font-variant-numeric: tabular-nums;
}
.sa-newbest {
  display: inline-block;
  margin: 4px 0 0;
  padding: 3px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff7a8a, #ff3d61);
  font-weight: 900;
  font-size: 13px;
  animation: sa-wiggle 1s ease-in-out infinite;
}
@keyframes sa-wiggle {
  50% {
    transform: rotate(-4deg) scale(1.06);
  }
}
.sa-stats {
  list-style: none;
  padding: 0;
  margin: 10px 0 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.sa-stats li {
  padding: 7px 4px;
  border-radius: 14px;
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sa-stats strong {
  display: block;
  color: #fff;
  font-size: 18px;
  letter-spacing: 0;
}

/* Upgrade cards */
.sa-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}
.sa-up {
  min-height: 44px;
  border: 0;
  border-radius: 18px;
  padding: 10px 8px 12px;
  background: linear-gradient(180deg, #33345a, #25263a);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 0 0 2px rgba(138, 109, 255, 0.35),
    0 6px 0 #15162a;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.15s cubic-bezier(0.2, 1.4, 0.4, 1);
  animation: sa-pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) backwards;
}
.sa-up:nth-child(2) {
  animation-delay: 0.08s;
}
.sa-up:nth-child(3) {
  animation-delay: 0.16s;
}
.sa-up:hover {
  transform: translateY(-4px);
}
.sa-up canvas {
  width: 64px;
  height: 64px;
}
.sa-up-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.sa-up-name {
  font-weight: 900;
  font-size: 15px;
}
.sa-up-desc {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.2;
}
.sa-pips {
  display: flex;
  gap: 3px;
  min-height: 8px;
}
.sa-pips i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3b3d58;
}
.sa-pips i.on {
  background: var(--gold);
}

/* Hat shop */
.sa-hats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0 14px;
}
.sa-hat {
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  padding: 6px 4px 8px;
  background: var(--panel-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.sa-hat canvas {
  width: 56px;
  height: 56px;
}
.sa-hat-name {
  font-size: 12px;
  font-weight: 900;
}
.sa-hat-price {
  font-size: 12px;
  font-weight: 800;
  color: var(--gold);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.sa-hat-price .sa-coin {
  width: 11px;
  height: 11px;
}
.sa-hat.is-owned .sa-hat-price {
  color: var(--muted);
}
.sa-hat.is-equipped {
  box-shadow:
    inset 0 0 0 2px var(--accent-2),
    0 0 14px rgba(104, 66, 255, 0.45);
}
.sa-hat.is-equipped .sa-hat-price {
  color: #b9a8ff;
}
.sa-hat.is-locked canvas {
  opacity: 0.7;
}
.sa-hat.is-shake {
  animation: sa-shake 0.35s;
}
@keyframes sa-shake {
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

.sa-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 5px;
  background: var(--secondary);
  color: #fff;
  font: inherit;
  font-size: 11px;
  box-shadow: 0 2px 0 #15162a;
}

@media (max-width: 600px) {
  .sa-chip strong {
    font-size: 16px;
  }
  .sa-chip > span {
    font-size: 9px;
  }
  .sa-cards {
    grid-template-columns: 1fr;
  }
  .sa-up {
    flex-direction: row;
    text-align: left;
    padding: 8px 12px;
  }
  .sa-up canvas {
    width: 52px;
    height: 52px;
    flex: none;
  }
  .sa-up-text {
    align-items: flex-start;
  }
  .sa-hats {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .sa-hat canvas {
    width: 44px;
    height: 44px;
  }
  .sa-title {
    font-size: 30px;
  }
  .sa-help {
    display: none;
  }
}
@media (max-width: 360px) {
  .sa-hats {
    grid-template-columns: repeat(3, 1fr);
  }
  .sa-hud {
    gap: 4px;
  }
}

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