:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  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 {
  margin: 0;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
}
body {
  padding: 8px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 3px solid #b8a6ff;
  outline-offset: 3px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sr-hide {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
[hidden] {
  display: none !important;
}

/* ---------- shell & HUD ---------- */
.mq-shell {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 10px;
  border-radius: 24px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(104, 66, 255, 0.22), transparent 60%),
    linear-gradient(180deg, #1a1b2e, #141526);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 60px rgba(0, 0, 0, 0.45);
}
.mq-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.mq-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.mq-logo {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 4px 10px rgba(104, 66, 255, 0.5));
}
.mq-brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.mq-chips {
  display: flex;
  gap: 6px;
  flex: 1 1 auto;
  justify-content: center;
  min-width: 0;
  flex-wrap: wrap;
}
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 44px;
  padding: 3px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2a2b40, #212233);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 rgba(0, 0, 0, 0.3);
  line-height: 1.05;
}
.chip span {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.chip strong {
  font-size: 1.12rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.chip-coins strong {
  color: #ffd45e;
}
.chip-level strong {
  color: #c5b6ff;
}
.chip-hearts,
.chip-keys {
  flex-direction: row;
  gap: 3px;
}
.chip-hearts strong,
.chip-keys strong {
  display: flex;
  gap: 3px;
  align-items: center;
}
.chip-keys strong:empty::after {
  content: "No keys";
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 800;
}
.chip svg {
  width: 22px;
  height: 22px;
  display: block;
}
.chip .heart-empty {
  opacity: 0.28;
  filter: grayscale(1);
}
.chip .pop {
  animation: pop 0.35s ease-out;
}
.chip.bump {
  animation: chip-bump 0.35s ease-out;
}
@keyframes pop {
  0% {
    transform: scale(0.3);
  }
  60% {
    transform: scale(1.35);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes chip-bump {
  40% {
    transform: scale(1.12);
  }
}
.mq-tools {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.icon-btn:active {
  transform: translateY(2px);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
}
.icon-btn .snd-off {
  display: none;
}
.icon-btn[aria-pressed="false"] .snd-off {
  display: inline;
}
.icon-btn[aria-pressed="false"] .snd-wave {
  display: none;
}

/* ---------- stage ---------- */
.mq-stage {
  position: relative;
  width: 100%;
  height: 460px;
  border-radius: 20px;
  overflow: hidden;
  background: #07060f;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.05),
    0 10px 30px rgba(0, 0, 0, 0.5);
}
.mq-stage.shake {
  animation: shake 0.28s ease-in-out;
}
@keyframes shake {
  20% {
    transform: translateX(-6px);
  }
  45% {
    transform: translateX(5px);
  }
  70% {
    transform: translateX(-3px);
  }
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}
#board:focus-visible {
  box-shadow: inset 0 0 0 3px #b8a6ff;
}
.mq-toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -10px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(20, 18, 40, 0.88);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 6px 18px rgba(0, 0, 0, 0.4);
  font-size: 0.95rem;
  font-weight: 900;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}
.mq-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: radial-gradient(circle at 50% 40%, rgba(40, 26, 90, 0.72), rgba(7, 6, 15, 0.9));
  backdrop-filter: blur(3px);
  z-index: 5;
}
.overlay-card {
  width: min(380px, 100%);
  padding: 20px 20px 22px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, #25264a, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 20px 50px rgba(0, 0, 0, 0.55);
  animation: card-in 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes card-in {
  from {
    transform: scale(0.8) translateY(12px);
    opacity: 0;
  }
}
.overlay-art {
  width: 150px;
  height: 100px;
  display: block;
  margin: -4px auto 4px;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.4));
}
.overlay-card h2 {
  margin: 0 0 6px;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff, #c9bcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.4;
}
.over-kicker {
  color: #ffd45e !important;
  font-weight: 900 !important;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.85rem;
  margin-bottom: 4px !important;
}
.over-kicker-bad {
  color: #ff7a93 !important;
}
.over-label {
  margin-bottom: 0 !important;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.over-score {
  font-size: 3.4rem;
  line-height: 1;
  font-weight: 900;
  color: #fff !important;
  margin: 2px 0 10px !important;
  text-shadow: 0 4px 0 #3b2a99;
}
.over-stats {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}
.over-stats div {
  flex: 1 1 0;
  padding: 8px 6px;
  border-radius: 14px;
  background: #212233;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.over-stats span {
  display: block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.over-stats strong {
  font-size: 1.3rem;
  font-weight: 900;
}
.over-note {
  color: #ff9fb2 !important;
  font-size: 0.9rem;
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 24px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 1rem;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.12s ease;
}
.pill:active {
  transform: translateY(3px);
}
.pill-primary {
  background: linear-gradient(180deg, #8a6bff, #6842ff);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 5px 0 #3b21a8,
    0 10px 24px rgba(104, 66, 255, 0.45);
}
.pill-primary:active {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 #3b21a8;
}
.pill-secondary {
  margin-top: 12px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 0 rgba(0, 0, 0, 0.35);
}
.pill-big {
  min-width: 200px;
  min-height: 54px;
  font-size: 1.2rem;
}
.overlay-card .pill-secondary {
  display: flex;
  margin: 12px auto 0;
}

/* ---------- D-pad (touch) ---------- */
.mq-dpad {
  display: none;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(2, 54px);
  gap: 6px;
  justify-content: center;
  margin: 10px auto 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #34355a, #262740);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: none;
}
.pad svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.pad.active,
.pad:active {
  transform: translateY(3px);
  background: linear-gradient(180deg, #8a6bff, #6842ff);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25);
}
.pad-up {
  grid-column: 2;
  grid-row: 1;
}
.pad-left {
  grid-column: 1;
  grid-row: 2;
}
.pad-down {
  grid-column: 2;
  grid-row: 2;
}
.pad-right {
  grid-column: 3;
  grid-row: 2;
}
@media (pointer: coarse) {
  .mq-dpad {
    display: grid;
  }
}

.mq-help {
  margin: 10px 4px 2px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.6;
}
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  font: inherit;
  font-size: 0.78rem;
  color: #fff;
  text-align: center;
}
@media (pointer: coarse) {
  .mq-help {
    display: none;
  }
}

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  body {
    padding: 4px;
  }
  .mq-shell {
    padding: 8px;
    border-radius: 18px;
  }
  .mq-hud {
    flex-wrap: wrap;
    gap: 8px;
  }
  .mq-brand {
    flex: 1 1 auto;
  }
  .mq-brand h1 {
    font-size: 1.1rem;
  }
  .mq-logo {
    width: 30px;
    height: 30px;
  }
  .mq-chips {
    order: 3;
    flex: 1 1 100%;
    gap: 5px;
    flex-wrap: nowrap;
  }
  .chip {
    min-width: 0;
    flex: 1 1 auto;
    padding: 3px 6px;
    height: 42px;
  }
  .chip span {
    font-size: 0.56rem;
  }
  .chip strong {
    font-size: 1rem;
  }
  .chip svg {
    width: 16px;
    height: 16px;
  }
  .chip-keys strong:empty::after {
    content: "–";
  }
  .icon-btn {
    width: 42px;
    height: 42px;
  }
  .overlay-card h2 {
    font-size: 1.7rem;
  }
  .over-score {
    font-size: 2.8rem;
  }
}
@media (max-width: 360px) {
  .chip-best {
    display: none;
  }
  .mq-dpad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 50px);
  }
}

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