/* Cluster engine (res/games/cluster.js). Every class starts with bq-cl-.
   Motion: transform and opacity only (filter for glows); drops and pops are
   cut to near-instant under prefers-reduced-motion by brook.css. */

.bq-cl {
  --bq-cl-gap: clamp(2px, 0.6vw, 5px);
  --bq-cl-fall-ease: cubic-bezier(0.34, 0.02, 0.3, 1.12);
  position: relative;
  display: grid;
  gap: var(--bq-s3);
  width: min(100%, 560px, max(300px, 100dvh - 330px));
  margin-inline: auto;
}

/* ------------------------------------------------------------------ HUD */
.bq-cl-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bq-s3);
  padding: 6px 6px 6px var(--bq-s3);
  border-radius: var(--bq-r-pill);
  background: linear-gradient(180deg, rgba(10, 33, 36, 0.88), rgba(6, 23, 25, 0.92));
  border: 1px solid var(--bq-line-2);
  box-shadow: var(--bq-shadow-1);
}

.bq-cl-ladder {
  display: flex;
  align-items: center;
  gap: var(--bq-s2);
  min-width: 0;
}

.bq-cl-ladder__cap,
.bq-cl-meter__cap {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bq-faint);
}

.bq-cl-ladder__steps {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bq-cl-rung {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 30px;
  padding: 0 6px;
  border-radius: var(--bq-r-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bq-line);
  color: var(--bq-faint);
  font-family: var(--bq-font-display);
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: transform var(--bq-med) var(--bq-ease-out), background-color var(--bq-med) var(--bq-ease-out),
    color var(--bq-med) var(--bq-ease-out), box-shadow var(--bq-med) var(--bq-ease-out);
}

.bq-cl-rung.is-past {
  color: var(--bq-gold);
  border-color: rgba(255, 207, 90, 0.3);
}

.bq-cl-rung.is-on {
  background: linear-gradient(180deg, var(--bq-coral-2), var(--bq-coral));
  border-color: transparent;
  color: var(--bq-on-coral);
  box-shadow: 0 0 0 3px rgba(255, 123, 92, 0.18), 0 6px 18px rgba(255, 123, 92, 0.45);
}

.bq-cl-rung.is-raise {
  animation: bq-cl-raise 380ms var(--bq-ease-out);
}

@keyframes bq-cl-raise {
  0% { transform: scale(0.9); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.bq-cl-meter {
  display: grid;
  justify-items: end;
  gap: 0;
  padding: 2px var(--bq-s4) 2px var(--bq-s3);
  border-radius: var(--bq-r-pill);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 207, 90, 0.18);
  min-width: 110px;
}

.bq-cl-meter__cap { font-size: 10px; line-height: 1.3; }

.bq-cl-meter__value {
  font-family: var(--bq-font-display);
  font-size: 19px;
  font-weight: 900;
  line-height: 1.15;
  color: var(--bq-gold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 14px rgba(255, 207, 90, 0.35);
}

.bq-cl-meter.is-bump .bq-cl-meter__value {
  animation: bq-cl-bump 300ms var(--bq-ease-out);
}

@keyframes bq-cl-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* ------------------------------------------------------------------ board */
.bq-cl-frame {
  position: relative;
  padding: clamp(6px, 1.4vw, 12px);
  border-radius: calc(var(--bq-r-l) + 4px);
  background:
    linear-gradient(160deg, rgba(20, 52, 57, 0.92), rgba(6, 23, 25, 0.96)) padding-box,
    linear-gradient(140deg, rgba(255, 207, 90, 0.75), rgba(255, 123, 92, 0.55) 40%, rgba(95, 227, 181, 0.35) 75%, rgba(255, 207, 90, 0.6)) border-box;
  border: 2px solid transparent;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.bq-cl-board {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--bq-r);
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, rgba(95, 227, 181, 0.1), transparent 60%), rgba(3, 14, 16, 0.55);
  box-shadow: inset 0 2px 18px rgba(0, 0, 0, 0.55);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.bq-cl-tiles,
.bq-cl-cells,
.bq-cl-fx {
  position: absolute;
  inset: 0;
}

.bq-cl-tiles {
  display: grid;
  grid-template-columns: repeat(var(--bq-cl-cols), 1fr);
  grid-auto-rows: 1fr;
  gap: var(--bq-cl-gap);
  padding: var(--bq-cl-gap);
}

.bq-cl-tile {
  border-radius: 22%;
  background: linear-gradient(180deg, rgba(173, 232, 220, 0.07), rgba(173, 232, 220, 0.025));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -2px 6px rgba(0, 0, 0, 0.25);
}

.bq-cl-fx { pointer-events: none; z-index: 3; }

/* One piece. The cell moves (fall), the inner symbol pops and glows. */
.bq-cl-cell {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--bq-cl-cols));
  height: calc(100% / var(--bq-cl-cols));
  padding: calc(var(--bq-cl-gap) + 1px);
  transform: translate3d(calc(var(--c) * 100%), calc(var(--r) * 100%), 0);
  transition-property: transform, opacity;
  transition-duration: 0ms, 0ms;
  transition-timing-function: var(--bq-cl-fall-ease), ease-out;
  will-change: transform;
  z-index: 1;
}

.bq-cl-cell.is-leaving {
  opacity: 0;
  transition-timing-function: cubic-bezier(0.5, 0, 0.75, 0.3), ease-out;
}

.bq-cl-sym {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transform-origin: 50% 85%;
}

.bq-cl-sym img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}

/* Stand-in tile while a symbol image is missing. */
.bq-cl-sym--plain {
  border-radius: 24%;
  background: radial-gradient(80% 70% at 35% 25%, rgba(255, 255, 255, 0.55), transparent 55%),
    linear-gradient(160deg, var(--tint), color-mix(in srgb, var(--tint) 55%, #06171a));
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.25), 0 3px 6px rgba(0, 0, 0, 0.35);
  color: rgba(6, 23, 25, 0.82);
  font-family: var(--bq-font-display);
  font-size: clamp(14px, 3.4vw, 24px);
  font-weight: 900;
}

.bq-cl-cell.is-landed .bq-cl-sym {
  animation: bq-cl-land 260ms var(--bq-ease-out);
}

@keyframes bq-cl-land {
  0% { transform: scale(1.06, 0.88); }
  60% { transform: scale(0.97, 1.04); }
  100% { transform: scale(1); }
}

.bq-cl-cell.is-wild .bq-cl-sym img {
  filter: drop-shadow(0 0 6px rgba(255, 207, 90, 0.65)) drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}

.bq-cl-cell.is-hit { z-index: 2; }

.bq-cl-cell.is-hit::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 24%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--tint) 55%, transparent), transparent);
  opacity: 0;
  animation: bq-cl-halo 620ms var(--bq-ease-out) forwards;
}

.bq-cl-cell.is-hit .bq-cl-sym {
  animation: bq-cl-hit 620ms var(--bq-ease-out) forwards;
}

.bq-cl-cell.is-hit .bq-cl-sym img {
  filter: drop-shadow(0 0 8px var(--tint)) drop-shadow(0 0 2px #fff) brightness(1.12);
}

@keyframes bq-cl-hit {
  0% { transform: scale(1); }
  35% { transform: scale(1.16) rotate(-3deg); }
  65% { transform: scale(1.06) rotate(2deg); }
  100% { transform: scale(1.1); }
}

@keyframes bq-cl-halo {
  to { opacity: 1; }
}

.bq-cl-cell.is-popping .bq-cl-sym {
  animation: bq-cl-pop 300ms var(--bq-ease-out) forwards;
}

.bq-cl-cell.is-popping::before { animation: bq-cl-halo-out 220ms ease-out forwards; }

@keyframes bq-cl-halo-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes bq-cl-pop {
  0% { transform: scale(1.1); opacity: 1; }
  40% { transform: scale(1.32); opacity: 1; }
  100% { transform: scale(0.2); opacity: 0; }
}

/* Floating "+120" over a cluster. */
.bq-cl-float {
  position: absolute;
  padding: 3px 10px;
  border-radius: var(--bq-r-pill);
  background: rgba(6, 23, 25, 0.82);
  border: 1px solid rgba(255, 207, 90, 0.55);
  color: var(--bq-gold);
  font-family: var(--bq-font-display);
  font-size: clamp(13px, 2.4vw, 17px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), 0 0 18px rgba(255, 207, 90, 0.25);
  transform: translate(-50%, -50%);
  animation: bq-cl-float 1400ms var(--bq-ease-out) forwards;
}

.bq-cl-float.is-big {
  background: linear-gradient(180deg, var(--bq-gold), #ffb43a);
  color: var(--bq-on-gold);
  border-color: transparent;
  font-size: clamp(15px, 2.8vw, 20px);
}

@keyframes bq-cl-float {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  24% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -95%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.96); }
}

.bq-cl-spark {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 25%, var(--tint) 45%, transparent 72%);
  box-shadow: 0 0 10px var(--tint);
  pointer-events: none;
}

.bq-cl-spark.is-star {
  width: 13px;
  height: 13px;
  border-radius: 0;
  background: linear-gradient(135deg, #fff, var(--tint));
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  box-shadow: none;
}

/* Short shake of the frame on a strong cluster, and the cascade badge. */
.bq-cl-frame.is-thump { animation: bq-cl-thump 320ms var(--bq-ease-out); }

@keyframes bq-cl-thump {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-1px, 1px); }
  100% { transform: translate(0, 0); }
}

.bq-cl-cascade {
  position: absolute;
  left: 50%;
  top: 50%;
  padding: 8px 20px;
  border-radius: var(--bq-r-pill);
  background: linear-gradient(180deg, var(--bq-coral-2), var(--bq-coral));
  color: var(--bq-on-coral);
  font-family: var(--bq-font-display);
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 30px rgba(255, 123, 92, 0.5);
  transform: translate(-50%, -50%);
  animation: bq-cl-cascade 1000ms var(--bq-ease-out) forwards;
  z-index: 4;
}

@keyframes bq-cl-cascade {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(0.98); }
}

/* ------------------------------------------------------------------ tier overlay */
.bq-cl-tier {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  border-radius: calc(var(--bq-r-l) + 4px);
  background: radial-gradient(70% 55% at 50% 45%, rgba(10, 33, 36, 0.72), rgba(3, 12, 13, 0.9));
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 180ms ease-out;
  overflow: hidden;
}

.bq-cl-tier.is-in { opacity: 1; transition-duration: 260ms; }

.bq-cl-tier__glow {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 150%;
  aspect-ratio: 1;
  background: conic-gradient(from 0deg, rgba(255, 207, 90, 0.16), transparent 12%, rgba(255, 123, 92, 0.14) 25%, transparent 37%,
    rgba(255, 207, 90, 0.16) 50%, transparent 62%, rgba(255, 123, 92, 0.14) 75%, transparent 87%, rgba(255, 207, 90, 0.16));
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: bq-cl-turn 14s linear infinite;
  pointer-events: none;
}

@keyframes bq-cl-turn {
  to { transform: translate(-50%, -50%) rotate(1turn); }
}

.bq-cl-tier__word,
.bq-cl-tier__value,
.bq-cl-tier__sub,
.bq-cl-tier__hint {
  position: relative;
  margin: 0;
}

.bq-cl-tier__word {
  font-family: var(--bq-font-display);
  font-size: clamp(34px, 8vw, 64px);
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1;
  background: linear-gradient(180deg, #fff3c4 10%, var(--bq-gold) 45%, #ff9f43 75%, var(--bq-coral));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgba(90, 30, 10, 0.55)) drop-shadow(0 0 22px rgba(255, 180, 60, 0.45));
}

.bq-cl-tier.is-in .bq-cl-tier__word { animation: bq-cl-word 520ms var(--bq-ease-out); }

@keyframes bq-cl-word {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.bq-cl-tier__value {
  font-family: var(--bq-font-display);
  font-size: clamp(28px, 6vw, 46px);
  font-weight: 900;
  color: var(--bq-ink);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 24px rgba(95, 227, 181, 0.35);
}

.bq-cl-tier__sub {
  color: var(--bq-mint);
  font-weight: 800;
}

.bq-cl-tier__hint {
  margin-top: var(--bq-s3);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bq-faint);
}

.bq-cl-tier[data-tier="superb"] .bq-cl-tier__word {
  background-image: linear-gradient(180deg, #ffffff 5%, #ffe08a 35%, var(--bq-gold) 55%, var(--bq-coral) 90%);
}

.bq-cl-tier[data-tier="sensational"] .bq-cl-tier__word {
  background-image: linear-gradient(180deg, #ffffff 5%, #ffd0c2 30%, var(--bq-coral-2) 55%, #ff5a7a 90%);
}

/* ------------------------------------------------------------------ deck buttons */
.bq-cl-go { min-width: 170px; }

.bq-cl-quick[aria-pressed="true"] {
  background: rgba(255, 207, 90, 0.14);
  border-color: rgba(255, 207, 90, 0.55);
  color: var(--bq-gold);
}

/* ------------------------------------------------------------------ narrow screens */
@media (max-width: 520px) {
  .bq-cl { gap: var(--bq-s2); }
  .bq-cl-hud { padding: 4px 4px 4px 10px; gap: var(--bq-s2); }
  .bq-cl-ladder__cap { display: none; }
  .bq-cl-rung { min-width: 0; width: 34px; height: 28px; padding: 0; font-size: 13px; }
  .bq-cl-meter { min-width: 0; padding: 2px 12px 2px 10px; }
  .bq-cl-meter__value { font-size: 17px; }
  .bq-cl-frame { border-radius: var(--bq-r-l); }
}

@media (prefers-reduced-motion: reduce) {
  .bq-cl-tier__glow { animation: none; }
}
