:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  --gap: 4px;
  --board: 440px;
  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;
  min-width: 0;
  width: 100%;
  background: var(--bg);
  color: var(--text);
}
body {
  padding: 10px;
  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;
}

/* ---------- shell & HUD ---------- */
.bp-shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 12px;
  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);
}
.bp-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.bp-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  margin-right: auto;
}
.bp-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff 30%, #c9bcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.bp-logo {
  display: grid;
  grid-template-columns: repeat(2, 13px);
  gap: 2px;
  flex: none;
}
.bp-logo i,
.overlay-logo i {
  display: block;
  aspect-ratio: 1;
  border-radius: 28%;
}
.bp-chips {
  display: flex;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  height: 44px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
.chip span {
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.1;
}
.chip strong {
  font-size: 18px;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.chip-score {
  min-width: 92px;
  background: linear-gradient(180deg, #7b5bff, #5330e6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.25),
    0 6px 16px rgba(104, 66, 255, 0.35);
}
.chip-score span {
  color: #ddd4ff;
}
.chip-best strong {
  color: #ffd35c;
}
.chip-combo.hot {
  background: linear-gradient(180deg, #ff9d3d, #f0521f);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 6px 16px rgba(255, 110, 40, 0.4);
}
.chip-combo.hot span {
  color: #ffe6d1;
}
.bump {
  animation: bump 0.32s ease-out;
}
@keyframes bump {
  40% {
    transform: scale(1.14);
  }
}
.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.12s;
}
.icon-btn:hover {
  background: #34354b;
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ---------- stage ---------- */
.bp-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.board-wrap {
  position: relative;
  width: min(100%, var(--board));
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--gap);
  padding: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, #1c1d31, #161728);
  box-shadow:
    inset 0 2px 10px rgba(0, 0, 0, 0.5),
    0 0 0 2px #2b2c45,
    0 14px 40px rgba(0, 0, 0, 0.4);
  touch-action: none;
  user-select: none;
}
.board.shake {
  animation: shake 0.36s ease-in-out;
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}
.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 22%;
  background: #25263b;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.45),
    inset 0 -1px 0 rgba(255, 255, 255, 0.03);
}

/* Glossy jewel blocks (shared by board, pieces, logo) */
.c1,
.g1 {
  --a: #ff7a8a;
  --b: #e8234a;
  --glow: rgba(255, 60, 100, 0.6);
}
.c2,
.g2 {
  --a: #ffb65c;
  --b: #f06a13;
  --glow: rgba(255, 140, 40, 0.6);
}
.c3,
.g3 {
  --a: #ffe98a;
  --b: #f3b400;
  --glow: rgba(255, 210, 40, 0.6);
}
.c4,
.g4 {
  --a: #7ff5a0;
  --b: #16b85a;
  --glow: rgba(40, 220, 110, 0.6);
}
.c5,
.g5 {
  --a: #7cecff;
  --b: #0ea5d8;
  --glow: rgba(40, 200, 255, 0.6);
}
.c6,
.g6 {
  --a: #8fa8ff;
  --b: #3553f0;
  --glow: rgba(70, 110, 255, 0.6);
}
.c7,
.g7 {
  --a: #e39bff;
  --b: #a32ee6;
  --glow: rgba(190, 70, 255, 0.6);
}
.block,
.cell[class*=" c"],
.bp-logo i,
.overlay-logo i[class],
.fx-flash {
  background:
    radial-gradient(
      circle at 28% 24%,
      rgba(255, 255, 255, 0.75) 0 9%,
      rgba(255, 255, 255, 0) 24%
    ),
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.28) 0 46%,
      rgba(255, 255, 255, 0) 47%
    ),
    linear-gradient(150deg, var(--a), var(--b));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -3px 0 rgba(0, 0, 0, 0.22),
    inset 2px 0 0 rgba(255, 255, 255, 0.12),
    0 3px 6px rgba(0, 0, 0, 0.35);
}
.cell.ghost {
  background: linear-gradient(150deg, var(--a), var(--b));
  opacity: 0.45;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
}
.cell.bad {
  background: rgba(255, 70, 90, 0.28);
  box-shadow: inset 0 0 0 2px rgba(255, 90, 110, 0.75);
}
.cell.hint {
  --a: var(--ha);
  --b: var(--hb);
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: -2px;
  animation: hint 0.6s ease-in-out infinite alternate;
}
.cell.hint:not([class*=" c"]):not(.ghost) {
  background: linear-gradient(150deg, var(--ha), var(--hb));
  opacity: 0.55;
}
@keyframes hint {
  from {
    filter: brightness(1.1);
  }
  to {
    filter: brightness(1.5) drop-shadow(0 0 8px rgba(255, 255, 255, 0.7));
  }
}
.cell.pop {
  animation: pop 0.28s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes pop {
  0% {
    transform: scale(0.6);
  }
  100% {
    transform: scale(1);
  }
}
.cell.dead {
  filter: grayscale(1) brightness(0.6);
  transition: filter 0.3s;
}

/* ---------- tray & pieces ---------- */
.tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(100%, var(--board));
}
.slot {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 112px;
  padding: 8px;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition:
    background 0.15s,
    box-shadow 0.15s;
}
.slot:disabled {
  cursor: default;
}
.slot.selected {
  background: #2a2560;
  box-shadow:
    inset 0 0 0 3px var(--accent),
    0 0 20px rgba(104, 66, 255, 0.45);
}
.slot .key {
  position: absolute;
  top: 7px;
  left: 10px;
  font-size: 11px;
  color: #6f7190;
}
.piece {
  display: grid;
  gap: calc(var(--mini, 22px) * 0.12);
  pointer-events: none;
  transition:
    transform 0.15s,
    opacity 0.2s,
    filter 0.2s;
}
.piece .block,
.piece .hole {
  width: var(--mini, 22px);
  height: var(--mini, 22px);
  border-radius: 22%;
}
.slot.dragging .piece {
  opacity: 0.15;
}
.slot.lift .piece {
  transform: scale(1.12);
}
.slot.nofit .piece {
  filter: grayscale(0.9) brightness(0.6);
}
.slot.deal .piece {
  animation: deal 0.42s cubic-bezier(0.25, 1.5, 0.5, 1) backwards;
}
.slot[data-slot="1"].deal .piece {
  animation-delay: 0.07s;
}
.slot[data-slot="2"].deal .piece {
  animation-delay: 0.14s;
}
@keyframes deal {
  from {
    transform: translateY(24px) scale(0.3);
    opacity: 0;
  }
}
.slot.nope {
  animation: shake 0.36s ease-in-out;
}

.drag-piece {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  display: grid;
  pointer-events: none;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.45));
  will-change: transform;
}
.drag-piece .block,
.drag-piece .hole {
  border-radius: 22%;
}
.drag-piece.back {
  transition: transform 0.22s ease-in;
}

/* ---------- effects ---------- */
.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 5;
}
.fx-flash {
  position: absolute;
  border-radius: 22%;
  animation: flash 0.5s ease-out forwards;
}
@keyframes flash {
  0% {
    transform: scale(1);
    filter: brightness(2.4);
  }
  40% {
    transform: scale(1.12);
    filter: brightness(2.2);
    opacity: 1;
  }
  100% {
    transform: scale(0.2) rotate(25deg);
    opacity: 0;
  }
}
.fx-spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background: linear-gradient(150deg, var(--a), var(--b));
  box-shadow: 0 0 8px var(--glow);
  animation: spark 0.7s cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}
@keyframes spark {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.2);
    opacity: 0;
  }
}
.fx-beam {
  position: absolute;
  border-radius: 12px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.9),
    transparent
  );
  animation: beam 0.45s ease-out forwards;
  mix-blend-mode: screen;
}
.fx-beam.v {
  background: linear-gradient(
    180deg,
    transparent,
    rgba(255, 255, 255, 0.9),
    transparent
  );
}
@keyframes beam {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: scale(1.06, 1.6);
  }
}
.fx-beam.v {
  animation-name: beamv;
}
@keyframes beamv {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: scale(1.6, 1.06);
  }
}
.fx-points {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 2px 0 #3a1fb8,
    0 0 12px rgba(104, 66, 255, 0.9);
  animation: rise 0.9s ease-out forwards;
  white-space: nowrap;
}
@keyframes rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.6);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(1);
  }
}
.fx-banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: clamp(30px, 9vw, 52px);
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: #fff6c9;
  background: linear-gradient(180deg, #fff9d6 20%, #ffc53d 55%, #ff7a1a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 #8a2d00)
    drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5));
  animation: banner 1.1s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
.fx-banner.sub {
  top: 58%;
  font-size: clamp(18px, 5vw, 26px);
  background: linear-gradient(180deg, #fff 30%, #b9a8ff);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 2px 0 #3a1fb8)
    drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}
@keyframes banner {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(-8deg);
  }
  25% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08) rotate(-3deg);
  }
  75% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-3deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -80%) scale(0.95) rotate(-3deg);
  }
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: 20px;
  background: rgba(12, 12, 28, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fadein 0.3s ease-out;
}
.overlay[hidden] {
  display: none;
}
@keyframes fadein {
  from {
    opacity: 0;
  }
}
.overlay-card {
  text-align: center;
  animation: cardin 0.45s cubic-bezier(0.25, 1.4, 0.5, 1);
}
@keyframes cardin {
  from {
    transform: scale(0.8) translateY(10px);
    opacity: 0;
  }
}
.overlay h2 {
  margin: 10px 0 4px;
  font-size: clamp(32px, 9vw, 46px);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #fff 35%, #c3b3ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #3a1fb8);
}
.overlay p {
  margin: 0 auto 18px;
  max-width: 280px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}
.overlay-logo {
  display: inline-grid;
  grid-template-columns: repeat(3, 26px);
  gap: 4px;
  animation: float 2.4s ease-in-out infinite;
}
@keyframes float {
  50% {
    transform: translateY(-6px) rotate(-3deg);
  }
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  background: var(--secondary);
  transition: transform 0.12s;
}
.pill:active {
  transform: scale(0.95);
}
.pill-primary {
  background: linear-gradient(180deg, #8467ff, #5a33f0);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -4px 0 rgba(0, 0, 0, 0.25),
    0 10px 24px rgba(104, 66, 255, 0.5);
}
.pill-primary:hover {
  filter: brightness(1.08);
}
.pill-big {
  min-width: 180px;
  min-height: 56px;
  font-size: 20px;
}
.over-kicker {
  font-size: 20px !important;
  color: #ffb0bd !important;
  font-weight: 900 !important;
  margin-bottom: 8px !important;
}
.over-label {
  margin-bottom: 0 !important;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 12px !important;
}
.over-score {
  margin: 0 0 2px !important;
  font-size: 58px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  color: #fff !important;
  text-shadow:
    0 3px 0 #3a1fb8,
    0 0 24px rgba(104, 66, 255, 0.8);
}
.over-best {
  color: #ffd35c !important;
  margin-bottom: 12px !important;
}
.over-best.new {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  color: #2b1600 !important;
  background: linear-gradient(180deg, #ffe27a, #ffb000);
  animation: bump 0.6s ease-out 0.3s 2;
}
.over-stats {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}
.over-stats span {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}
.over-stats b {
  color: #fff;
}

.bp-help {
  margin: 12px 4px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 1.7;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35);
  color: #fff;
  font: inherit;
  font-size: 11px;
  text-align: center;
}

/* ---------- responsive ---------- */
@media (min-width: 700px) {
  .bp-shell {
    width: min(760px, 100%);
    padding: 14px 18px;
  }
  .bp-stage {
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    gap: 16px;
  }
  .board-wrap {
    width: min(var(--board), calc(100% - 196px));
  }
  .tray {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 1fr);
    width: 180px;
  }
  .slot {
    min-height: 0;
  }
}
@media (max-width: 520px) {
  body {
    padding: 6px;
  }
  .bp-shell {
    padding: 10px;
    border-radius: 18px;
  }
  .bp-hud {
    flex-wrap: wrap;
    gap: 8px;
  }
  .bp-brand {
    flex: 1 1 auto;
  }
  .bp-chips {
    order: 3;
    width: 100%;
  }
  .chip {
    flex: 1;
    min-width: 0;
    padding: 3px 6px;
  }
  .board {
    padding: 6px;
    border-radius: 16px;
  }
  :root {
    --gap: 3px;
  }
  .slot {
    min-height: 100px;
    border-radius: 16px;
  }
  .bp-help {
    font-size: 11px;
  }
}
@media (hover: none) {
  .bp-help {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .cell.hint {
    animation: none;
    filter: brightness(1.3);
  }
}
