:root {
  --cols: 8;
  --rows: 8;

  --bg-1: #050810;
  --bg-2: #0b1226;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f6f8ff;
  --muted: rgba(246, 248, 255, 0.68);

  --accent-1: #7c3aed;
  --accent-2: #2563eb;
  --gold: #fbbf24;
  --danger: #fb7185;

  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 18px;

  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.42);
  --shadow-md: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow-x: hidden;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    radial-gradient(1200px 800px at 15% 10%, rgba(124, 58, 237, 0.22), transparent 55%),
    radial-gradient(1000px 700px at 85% 85%, rgba(37, 99, 235, 0.22), transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

button {
  font: inherit;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  width: 38vmax;
  height: 38vmax;
  border-radius: 50%;
  filter: blur(72px);
  opacity: 0.42;
  animation: drift 16s ease-in-out infinite alternate;
}

.blob-1 {
  top: -12vmax;
  left: -9vmax;
  background: radial-gradient(circle at 30% 30%, #7c3aed, transparent 68%);
}

.blob-2 {
  right: -10vmax;
  bottom: -14vmax;
  background: radial-gradient(circle at 30% 30%, #2563eb, transparent 68%);
  animation-delay: -4s;
}

.blob-3 {
  left: 32%;
  bottom: -18vmax;
  width: 26vmax;
  height: 26vmax;
  opacity: 0.2;
  background: radial-gradient(circle at 30% 30%, #f59e0b, transparent 68%);
  animation-delay: -8s;
}

@keyframes drift {
  to {
    transform: translate3d(4vmax, -3vmax, 0) scale(1.08);
  }
}

.app {
  width: min(100%, 640px);
  display: grid;
  gap: 14px;
}

.hud {
  display: grid;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 24px;
  border-radius: 16px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: 0.045em;
  background: linear-gradient(90deg, #ffffff, #c4b5fd, #7dd3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 32px rgba(124, 58, 237, 0.22);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  padding: 10px 12px;
  text-align: center;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
}

.label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.value {
  display: inline-block;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.05;
}

.value.bump {
  animation: bump 0.25s ease;
}

@keyframes bump {
  30% {
    transform: scale(1.18);
  }
}

#movesStat.danger .value {
  color: var(--danger);
  text-shadow: 0 0 18px rgba(251, 113, 133, 0.5);
}

.board-wrap {
  position: relative;
  width: min(92vw, 520px);
  margin: 0 auto;
  aspect-ratio: 1;
  padding: 10px;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: rgba(4, 8, 18, 0.35);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 0 40px rgba(0, 0, 0, 0.3);
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size:
    calc(100% / var(--cols)) calc(100% / var(--rows));
}

.board.reshuffling {
  filter: blur(2px) saturate(0.75);
  transform: scale(0.99);
  transition: 0.25s ease;
}

.fx {
  position: absolute;
  inset: 10px;
  z-index: 30;
  pointer-events: none;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.combo-toast {
  position: absolute;
  left: 50%;
  top: 12%;
  z-index: 50;
  transform: translate(-50%, -8px) scale(0.9);
  opacity: 0;
  pointer-events: none;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 900;
  letter-spacing: 0.03em;
  color: #fff;
  text-shadow:
    0 0 18px rgba(251, 191, 36, 0.5),
    0 0 38px rgba(124, 58, 237, 0.4);
  transition: 0.22s ease;
}

.combo-toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.gem {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  transition: transform 0.24s cubic-bezier(0.2, 0.85, 0.25, 1.12);
  will-change: transform;
}

.gem-body {
  position: absolute;
  inset: 9%;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 24%;
  transform: scale(1);
  transition:
    transform 0.16s ease,
    filter 0.16s ease,
    opacity 0.18s ease;
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.28),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 18px rgba(0, 0, 0, 0.26);
}

.gem-body::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  top: 12%;
  height: 26%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0));
  filter: blur(1px);
  opacity: 0.75;
}

/* Цвета и форма камней */
.gem[data-type="0"] .gem-body {
  border-radius: 24%;
  background: radial-gradient(circle at 30% 25%, #ffd1dc, #ff2d55 70%);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.3),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(255, 45, 85, 0.35);
}

.gem[data-type="1"] .gem-body {
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #ffe3a3, #ef8354 72%);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.32),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(239, 131, 84, 0.35);
}

.gem[data-type="2"] .gem-body {
  border-radius: 32% 68% 30% 70% / 35% 30% 70% 65%;
  background: radial-gradient(circle at 30% 25%, #baffd4, #0f9d58 72%);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.3),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(16, 157, 88, 0.35);
}

.gem[data-type="3"] .gem-body {
  border-radius: 18%;
  background: radial-gradient(circle at 30% 25%, #cfe9ff, #2563eb 72%);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.32),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(37, 99, 235, 0.35);
}

.gem[data-type="4"] .gem-body {
  border-radius: 50% 50% 26% 26%;
  background: radial-gradient(circle at 30% 25%, #e5dbff, #7c3aed 72%);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.3),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(124, 58, 237, 0.35);
}

.gem[data-type="5"] .gem-body {
  border-radius: 34%;
  background: radial-gradient(circle at 30% 25%, #d9feff, #0891b2 72%);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.34),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(8, 145, 178, 0.35);
}

.gem.selected {
  z-index: 4;
}

.gem.selected .gem-body {
  transform: scale(1.08);
  animation: selectedPulse 1s ease-in-out infinite;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.86),
    0 0 26px rgba(255, 255, 255, 0.36),
    inset 0 5px 10px rgba(255, 255, 255, 0.3),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28);
}

@keyframes selectedPulse {
  50% {
    transform: scale(1.04);
  }
}

.gem.invalid .gem-body {
  animation: shake 0.24s ease;
  box-shadow:
    0 0 0 3px rgba(255, 80, 80, 0.78),
    0 0 22px rgba(255, 80, 80, 0.34),
    inset 0 5px 10px rgba(255, 255, 255, 0.28),
    inset 0 -9px 15px rgba(0, 0, 0, 0.28);
}

@keyframes shake {
  25% {
    transform: translateX(-6%);
  }
  75% {
    transform: translateX(6%);
  }
}

.gem.removing {
  z-index: 5;
}

.gem.removing .gem-body {
  animation: pop 0.26s ease forwards;
}

@keyframes pop {
  35% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(0.05) rotate(18deg);
    opacity: 0;
  }
}

.particle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: particle 0.68s ease-out forwards;
}

@keyframes particle {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translate(
        calc(-50% + var(--dx)),
        calc(-50% + var(--dy))
      )
      scale(0);
  }
}

.float-score {
  position: absolute;
  z-index: 40;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 18px rgba(255, 255, 255, 0.45),
    0 2px 10px rgba(0, 0, 0, 0.4);
  animation: floatUp 0.85s ease forwards;
}

@keyframes floatUp {
  to {
    transform: translate(-50%, calc(-50% - 34px)) scale(1.08);
    opacity: 0;
  }
}

.toolbar {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.hint {
  margin: 0;
  max-width: 480px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 16px;
  font-weight: 800;
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--border);
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.18);
}

.btn:active {
  transform: translateY(0) scale(0.985);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  box-shadow: 0 12px 24px rgba(124, 58, 237, 0.35);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 8, 18, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(100%, 420px);
  padding: 28px;
  text-align: center;
  border-radius: 28px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: panelIn 0.3s ease;
}

@keyframes panelIn {
  from {
    transform: translateY(14px) scale(0.96);
    opacity: 0;
  }
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 30px;
}

.final-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.final-score {
  margin: 8px 0 12px;
  font-size: 56px;
  font-weight: 900;
  background: linear-gradient(90deg, #fff, var(--gold), #fb7185);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.note {
  min-height: 20px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

@media (max-width: 520px) {
  body {
    padding: 12px;
  }

  .stats {
    gap: 8px;
  }

  .value {
    font-size: 20px;
  }

  .board-wrap {
    width: min(96vw, 520px);
    padding: 8px;
  }

  .fx {
    inset: 8px;
  }
}