:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8f73ff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  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);
}
body {
  padding: 10px;
  overflow-x: hidden;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

/* ---------- HUD ---------- */
.mj-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
}
.mj-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: clamp(17px, 2.6vw, 22px);
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.mj-logo {
  width: 22px;
  height: 28px;
  border-radius: 5px;
  background:
    radial-gradient(circle at 50% 50%, #e0364d 0 4px, transparent 4.5px),
    radial-gradient(circle at 50% 50%, #fff 0 6px, transparent 6.5px),
    radial-gradient(circle at 50% 50%, #2463d6 0 8px, transparent 8.5px),
    linear-gradient(150deg, #fffdf5, #ecdcb8);
  box-shadow:
    2px 2px 0 #cdb27a,
    4px 4px 0 #2f9b77,
    0 6px 12px rgba(0, 0, 0, 0.4);
  transform: rotate(-8deg);
}
.mj-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 2px 0 rgba(0, 0, 0, 0.35);
  font-weight: 800;
}
.chip span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.chip strong {
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.chip.bump strong {
  animation: bump 0.35s ease;
}
.chip-moves.low strong {
  color: #ffb347;
}
@keyframes bump {
  40% {
    transform: scale(1.3);
    color: #c8b9ff;
  }
}

/* ---------- Stage & board ---------- */
.mj-stage {
  position: relative;
  border-radius: 22px;
  background:
    radial-gradient(120% 90% at 50% 0%, #2c2466 0%, transparent 60%),
    radial-gradient(90% 80% at 50% 110%, #173c46 0%, transparent 65%),
    linear-gradient(180deg, #1c1d33, #14152a);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 -30px 60px rgba(0, 0, 0, 0.25),
    0 12px 30px rgba(0, 0, 0, 0.35);
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 260px;
  overflow: hidden;
}
.mj-board {
  position: relative;
  flex: none;
  --tw: 40px;
  --th: 52px;
  --d: 4px;
}
.mj-board.shake-board {
  animation: shake 0.4s ease;
}

.tile {
  position: absolute;
  left: calc(var(--pad) + var(--x) * var(--tw) / 2 - var(--z) * var(--d));
  top: calc(var(--pad) + var(--y) * var(--th) / 2 - var(--z) * var(--d));
  width: var(--tw);
  height: var(--th);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: calc(var(--tw) * 0.16);
  background: linear-gradient(150deg, #fffef9 0%, #faf1dc 45%, #efdfbb 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 3px rgba(150, 110, 50, 0.22),
    calc(var(--d) * 0.35) calc(var(--d) * 0.35) 0 #e6d3a6,
    calc(var(--d) * 0.7) calc(var(--d) * 0.7) 0 #d2b77e,
    var(--d) var(--d) 0 #bb9a5c,
    calc(var(--d) * 1.35) calc(var(--d) * 1.35) 0 #2f9b77,
    calc(var(--d) * 1.7) calc(var(--d) * 1.7) 0 #1f7358,
    calc(var(--d) * 1.7 + 2px) calc(var(--d) * 1.7 + 4px) 8px
      rgba(0, 0, 0, 0.45);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.12s ease,
    filter 0.18s ease,
    opacity 0.18s ease;
  touch-action: manipulation;
}
.tile svg {
  position: absolute;
  inset: 6% 7%;
  width: 86%;
  height: 88%;
  pointer-events: none;
}
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: rgba(70, 40, 0, var(--shade, 0));
  transition: background 0.18s ease;
}
.dim-blocked .tile.blocked::after {
  background: rgba(40, 28, 60, calc(var(--shade, 0) + 0.2));
}
.tile:focus-visible {
  outline: 3px solid #ffd84d;
  outline-offset: 2px;
}
.tile.selected {
  transform: translate(-2px, -3px);
  box-shadow:
    inset 0 0 0 3px var(--accent),
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    calc(var(--d) * 0.35) calc(var(--d) * 0.35) 0 #e6d3a6,
    calc(var(--d) * 0.7) calc(var(--d) * 0.7) 0 #d2b77e,
    var(--d) var(--d) 0 #bb9a5c,
    calc(var(--d) * 1.35) calc(var(--d) * 1.35) 0 #2f9b77,
    calc(var(--d) * 1.7) calc(var(--d) * 1.7) 0 #1f7358,
    0 0 0 3px var(--accent),
    0 0 22px 6px rgba(120, 84, 255, 0.85);
}
.tile.selected::after {
  background: rgba(104, 66, 255, 0.16);
}
.tile.hinted {
  animation: hint-pulse 0.9s ease-in-out infinite;
}
.tile.hinted::after {
  background: rgba(255, 214, 64, 0.2);
}
@keyframes hint-pulse {
  0%,
  100% {
    filter: drop-shadow(0 0 0 rgba(255, 210, 60, 0));
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(255, 210, 60, 1));
    transform: translateY(-2px);
  }
}
.tile.shake {
  animation: shake 0.36s ease;
}
@keyframes shake {
  20% {
    transform: translateX(-4px) rotate(-2deg);
  }
  40% {
    transform: translateX(4px) rotate(2deg);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(2px);
  }
}
.tile.vanish {
  pointer-events: none;
  animation: vanish 0.32s ease-in forwards;
}
@keyframes vanish {
  0% {
    transform: translate(-2px, -3px) scale(1);
    opacity: 1;
  }
  35% {
    transform: translate(-2px, -8px) scale(1.12);
    opacity: 1;
    filter: brightness(1.4);
  }
  100% {
    transform: translate(-2px, -12px) scale(0.4) rotate(8deg);
    opacity: 0;
  }
}
.tile.pop-in {
  animation: pop-in 0.35s cubic-bezier(0.3, 1.6, 0.5, 1) both;
  animation-delay: var(--delay, 0s);
}
@keyframes pop-in {
  from {
    transform: translateY(-18px) scale(0.6);
    opacity: 0;
  }
}
.tile[hidden] {
  display: none;
}

/* particles and floating text */
.spark {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--c, #ffd84d);
  box-shadow: 0 0 8px var(--c, #ffd84d);
  pointer-events: none;
  z-index: 9000;
  animation: spark 0.6s ease-out forwards;
}
@keyframes spark {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    opacity: 0;
  }
}
.float-text {
  position: absolute;
  z-index: 9100;
  pointer-events: none;
  font-weight: 900;
  font-size: 20px;
  color: #fff;
  text-shadow:
    0 2px 0 #4a2bd6,
    0 0 12px rgba(104, 66, 255, 0.9);
  transform: translate(-50%, -50%);
  animation: float-up 0.9s ease-out forwards;
  white-space: nowrap;
}
.float-text.combo {
  color: #ffe066;
  text-shadow:
    0 2px 0 #b8541b,
    0 0 12px rgba(255, 170, 40, 0.9);
}
@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.6);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -60%) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -160%) scale(1);
  }
}

/* ---------- Overlay ---------- */
.mj-overlay {
  position: absolute;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 10, 24, 0.62);
  backdrop-filter: blur(3px);
}
.mj-overlay[hidden] {
  display: none;
}
.mj-card {
  width: min(380px, 100%);
  padding: 20px 20px 18px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, #25264a, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 0 1px rgba(104, 66, 255, 0.35),
    0 20px 50px rgba(0, 0, 0, 0.55);
  animation: card-in 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes card-in {
  from {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
  }
}
.mj-card h2 {
  margin: 8px 0 6px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff, #c9bcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.mj-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.45;
}
.mj-card-art {
  display: flex;
  justify-content: center;
  gap: 6px;
  height: 64px;
  align-items: flex-end;
}
.mj-card-art .tile {
  position: relative;
  left: auto;
  top: auto;
  --tw: 40px;
  --th: 52px;
  --d: 4px;
  --z: 0;
  cursor: default;
  animation: bob 2.4s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes bob {
  50% {
    transform: translateY(-6px) rotate(var(--rot, 0deg));
  }
}
.mj-results {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  margin: 0 auto 16px;
  max-width: 240px;
  font-weight: 800;
  text-align: left;
}
.mj-results dt {
  color: var(--muted);
}
.mj-results dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.mj-results .total {
  font-size: 20px;
  font-weight: 900;
  color: #ffe066;
}
.mj-card-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.confetti {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  z-index: 9500;
  pointer-events: none;
  animation: confetti var(--t, 2.4s) linear forwards;
  animation-delay: var(--delay, 0s);
}
@keyframes confetti {
  to {
    transform: translate(var(--dx, 0), 110vh) rotate(var(--r, 540deg));
  }
}

/* ---------- Buttons ---------- */
.mj-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #33344a, var(--secondary));
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 3px 0 #17182a,
    0 6px 12px rgba(0, 0, 0, 0.3);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    opacity 0.15s ease;
}
.btn:hover {
  filter: brightness(1.12);
}
.btn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 1px 0 #17182a;
}
.btn:focus-visible {
  outline: 3px solid #ffd84d;
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}
.btn-primary {
  background: linear-gradient(180deg, #7d5bff, var(--accent));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 3px 0 #3d1fb8,
    0 8px 18px rgba(104, 66, 255, 0.4);
}
.btn-big {
  min-height: 52px;
  padding: 0 40px;
  font-size: 19px;
  font-weight: 900;
}
.btn-ico {
  font-size: 15px;
  line-height: 1;
}
.btn-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  font-size: 12px;
  font-weight: 900;
}
.btn[aria-pressed="false"] {
  opacity: 0.7;
}
.mj-help {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
kbd {
  display: inline-block;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--secondary);
  color: #fff;
  font: inherit;
  font-size: 11px;
  box-shadow: 0 2px 0 #17182a;
}

@media (max-width: 560px) {
  body {
    padding: 8px;
  }
  .mj-hud {
    justify-content: center;
  }
  .mj-chips {
    justify-content: center;
    gap: 5px;
  }
  .mj-chips {
    flex-wrap: nowrap;
    width: 100%;
  }
  .chip {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 4px 4px 5px;
    border-radius: 14px;
  }
  .chip span {
    font-size: 9px;
  }
  .chip strong {
    font-size: 15px;
  }
  .mj-stage {
    padding: 8px;
    border-radius: 18px;
  }
  .btn {
    padding: 0 12px;
    font-size: 13px;
  }
  .mj-help {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition: none !important;
  }
  .tile.hinted {
    animation: none;
  }
  .tile.hinted::after {
    background: rgba(255, 214, 64, 0.45);
  }
  .spark,
  .confetti,
  .float-text {
    display: none;
  }
}
.btn[hidden] {
  display: none;
}
