:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --gold: #ffd24a;
  --chrome: 112px;
  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: 8px 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 {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid #ffd84a;
  outline-offset: 2px;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #0b0c1a;
  color: #fff;
  font: inherit;
  font-size: 0.9em;
  text-align: center;
}

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

/* HUD */
.hud {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.brand-icon {
  width: 34px;
  height: 34px;
  flex: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.4));
}
.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.chips {
  display: flex;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
}
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #262740, #1d1e30);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 3px 0 #0b0c1a;
  line-height: 1.05;
}
.chip span {
  font-size: 0.62rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chip strong {
  font-size: 1.05rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.chip-score strong {
  color: var(--gold);
}
.chip.pop strong {
  animation: pop 0.28s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.chip-mode strong {
  font-size: 0.92rem;
  white-space: nowrap;
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.35);
  }
  100% {
    transform: scale(1);
  }
}
.hud-actions {
  display: flex;
  gap: 6px;
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 3px 0 #0b0c1a;
  cursor: pointer;
}
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.icon-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.icon-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 #0b0c1a;
}
#sound .icon-off,
#sound[aria-pressed="true"] .icon-on {
  display: none;
}
#sound[aria-pressed="true"] .icon-off {
  display: block;
}

/* Stage */
.stage {
  width: 100%;
  display: flex;
  justify-content: center;
}
.board {
  position: relative;
  width: min(100%, 560px, calc((100svh - var(--chrome)) * 0.8));
  height: clamp(340px, calc(100svh - var(--chrome)), 760px);
  min-width: 0;
  border-radius: 22px;
  overflow: hidden;
  background: #262a4a;
  box-shadow: 0 0 0 3px #2c2d45, 0 14px 40px rgba(0, 0, 0, 0.45);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.board.shake {
  animation: shake 0.26s ease-out;
}
@keyframes shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-6px, 2px);
  }
  50% {
    transform: translate(5px, -2px);
  }
  75% {
    transform: translate(-3px, 1px);
  }
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  outline: none;
}
canvas:focus-visible {
  outline: 3px solid #ffd84a;
  outline-offset: -3px;
}

/* Hint */
.hint {
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}
.hint[hidden] {
  display: none;
}
.hint span {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.78);
  font-size: 1rem;
  font-weight: 900;
}
.hint-hand {
  width: 64px;
  height: 64px;
  animation: tap 1.1s ease-in-out infinite;
}
.hint-ring {
  fill: none;
  stroke: #fff;
  stroke-width: 3;
  opacity: 0;
  transform-origin: 26px 14px;
  animation: ring 1.1s ease-out infinite;
}
@keyframes tap {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(8px) scale(0.92);
  }
}
@keyframes ring {
  0%,
  40% {
    opacity: 0;
    transform: scale(0.4);
  }
  50% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: scale(1.6);
  }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: linear-gradient(180deg, rgba(15, 16, 32, 0.35), rgba(15, 16, 32, 0.72));
  overflow-y: auto;
}
.overlay[hidden] {
  display: none;
}
.overlay-soft {
  background: rgba(15, 16, 32, 0.6);
}
.card {
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(38, 39, 64, 0.96), rgba(26, 27, 40, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 18px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: card-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.card-small {
  width: min(100%, 260px);
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.94);
  }
}
.card h2 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1.05;
}
.lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
}
.logo {
  height: 64px;
  display: grid;
  place-items: end center;
}
.logo-stack {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
}
.logo-stack i {
  display: block;
  width: 64px;
  height: 13px;
  margin-top: -1px;
  border-radius: 5px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 60%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 70%, #000));
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  animation: logo-drop 2.8s cubic-bezier(0.3, 1.5, 0.5, 1) infinite;
  animation-delay: var(--d);
}
.logo-stack i:nth-child(2) {
  width: 56px;
}
.logo-stack i:nth-child(3) {
  width: 50px;
}
.logo-stack i:nth-child(4) {
  width: 44px;
}
@keyframes logo-drop {
  0% {
    transform: translateY(-26px);
    opacity: 0;
  }
  18%,
  86% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.tabs {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 52px;
  padding: 8px 6px;
  border: 0;
  border-radius: 16px;
  background: var(--secondary);
  box-shadow: inset 0 0 0 2px transparent, 0 3px 0 #0b0c1a;
  cursor: pointer;
}
.tab b {
  font-size: 1rem;
  font-weight: 900;
}
.tab small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.tab[aria-pressed="true"] {
  background: linear-gradient(180deg, #3a2f7a, #2d2660);
  box-shadow: inset 0 0 0 2px var(--accent-2), 0 3px 0 #0b0c1a;
}
.tab[aria-pressed="true"] small {
  color: #d6ceff;
}

.city-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.city-panel[hidden] {
  display: none;
}
.level-pick {
  display: flex;
  align-items: center;
  gap: 8px;
}
.level-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.level-info strong {
  font-size: 1.05rem;
  font-weight: 900;
}
.level-info small {
  color: var(--muted);
  font-weight: 700;
}
.step-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow: 0 3px 0 #0b0c1a;
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}
.step-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.themes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.theme {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-height: 58px;
  padding: 4px;
  border: 0;
  border-radius: 14px;
  background: var(--sky);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12), 0 3px 0 #0b0c1a;
  cursor: pointer;
  overflow: hidden;
}
.theme::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 22px;
  height: 20px;
  background: var(--city);
  clip-path: polygon(0 100%, 0 40%, 14% 40%, 14% 10%, 30% 10%, 30% 55%, 44% 55%, 44% 0, 58% 0, 58% 35%, 74% 35%, 74% 20%, 88% 20%, 88% 60%, 100% 60%, 100% 100%);
}
.theme span {
  position: relative;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.7);
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}
.theme[aria-pressed="true"] {
  box-shadow: inset 0 0 0 3px #fff, 0 3px 0 #0b0c1a;
}
.theme:disabled {
  cursor: default;
  filter: grayscale(0.8) brightness(0.6);
}
.theme .lock {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 16px;
  height: 16px;
  fill: #fff;
}

.btn {
  min-height: 44px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.btn:active {
  transform: translateY(2px) scale(0.98);
}
.btn-primary {
  background: linear-gradient(180deg, #8466ff, var(--accent));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 0 #3b21b0, 0 10px 20px rgba(104, 66, 255, 0.35);
}
.btn-secondary {
  background: var(--secondary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 3px 0 #0b0c1a;
}
.btn-big {
  width: 100%;
  min-height: 54px;
  font-size: 1.3rem;
}
#play {
  animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe {
  50% {
    transform: scale(1.04);
  }
}
.stats-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.card-end {
  gap: 8px;
}
.end-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.end-score {
  margin: -4px 0 0;
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 4px 0 #a86d00, 0 10px 24px rgba(255, 190, 40, 0.35);
  animation: score-in 0.6s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes score-in {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
}
.end-badge {
  margin: 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff7aa6, #ff3f7a);
  box-shadow: 0 3px 0 #a3194a;
  font-weight: 900;
  animation: badge 1.2s ease-in-out infinite;
}
.end-badge[hidden],
.end-unlock[hidden] {
  display: none;
}
@keyframes badge {
  50% {
    transform: rotate(-3deg) scale(1.06);
  }
}
.end-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.end-stats div {
  display: flex;
  flex-direction: column;
  padding: 8px 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}
.end-stats span {
  color: var(--muted);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.end-stats strong {
  font-size: 1.2rem;
  font-weight: 900;
}
.end-unlock {
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(255, 210, 74, 0.2), rgba(255, 93, 143, 0.2));
  box-shadow: inset 0 0 0 2px rgba(255, 210, 74, 0.5);
  font-size: 0.9rem;
}
.end-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help {
  margin: 0;
  min-height: 22px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 560px) {
  .brand h1 {
    display: none;
  }
  .chips {
    margin-left: 0;
    flex: 1;
    justify-content: center;
  }
  .chip {
    min-width: 0;
    flex: 1;
    padding: 4px 6px;
  }
}
@media (max-width: 360px) {
  .brand {
    display: none;
  }
  .chip-mode strong {
    font-size: 0.8rem;
  }
  .card {
    padding: 14px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
  .logo-stack i,
  .hint-hand,
  #play {
    animation: none !important;
  }
}

@media (max-height: 640px) {
  .logo {
    display: none;
  }
  .card {
    gap: 8px;
    padding-top: 14px;
  }
}
