/* Quick Sort — 3×3 shelf stacks, drag + drop */

:root {
  /* System fonts first so UI is never Times if webfonts/CSS fail */
  --qs-font-display: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Outfit", sans-serif;
  --qs-font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "DM Sans", sans-serif;
  --qs-vignette: rgba(0, 0, 0, 0.52);
  --qs-grid-line: rgba(255, 255, 255, 0.045);
  --qs-fx-intensity: 1;
  --qs-glow-strength: 1;
  --qs-bg-a: rgba(124, 58, 237, 0.18);
  --qs-bg-b: rgba(8, 145, 178, 0.1);
  --qs-bg-c: rgba(225, 29, 72, 0.08);
  --qs-drop-ok: #22c55e;
  --qs-drop-ok-rgb: 34, 197, 94;
  --qs-danger: #ef4444;
  --qs-danger-rgb: 239, 68, 68;
  --qs-combo: #f59e0b;
  --qs-combo-rgb: 245, 158, 11;
  --qs-rush-a: #a78bfa;
  --qs-rush-b: #22d3ee;
}

html[data-qs-theme="sunset"] {
  --qs-bg-a: rgba(249, 115, 22, 0.18);
  --qs-bg-b: rgba(244, 63, 94, 0.12);
  --qs-bg-c: rgba(250, 204, 21, 0.1);
  --qs-drop-ok: #10b981;
  --qs-drop-ok-rgb: 16, 185, 129;
  --qs-danger: #fb7185;
  --qs-danger-rgb: 251, 113, 133;
  --qs-combo: #f97316;
  --qs-combo-rgb: 249, 115, 22;
  --qs-rush-a: #f59e0b;
  --qs-rush-b: #fb7185;
}

html, body {
  margin: 0;
  padding: 0;
  color: #ffffff;
  font-family: var(--qs-font-ui);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  min-height: 100vh;
}

.qs-atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, var(--qs-bg-a), transparent 55%),
    radial-gradient(ellipse 80% 60% at 100% 100%, var(--qs-bg-b), transparent 45%),
    radial-gradient(ellipse 60% 50% at 0% 80%, var(--qs-bg-c), transparent 40%),
    radial-gradient(ellipse 85% 75% at 50% 50%, transparent 35%, var(--qs-vignette) 100%);
  box-shadow: inset 0 0 min(100vw, 900px) rgba(0, 0, 0, 0.35);
  opacity: 1;
}

.qs-atmosphere::before {
  content: "";
  position: absolute;
  inset: -15%;
  pointer-events: none;
  background:
    radial-gradient(circle at 28% 38%, rgba(124, 58, 237, 0.22), transparent 42%),
    radial-gradient(circle at 72% 58%, rgba(8, 145, 178, 0.14), transparent 48%),
    radial-gradient(circle at 48% 88%, rgba(225, 29, 72, 0.1), transparent 40%);
  opacity: 0.9;
  animation: qs-atmo-drift 22s ease-in-out infinite alternate;
  will-change: transform;
}

.qs-atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

@keyframes qs-atmo-drift {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(2.5%, -1.5%) scale(1.04);
  }
}

.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: min(100vh, 100dvh);
  padding: clamp(66px, 9dvh, 90px) 10px 14px;
  box-sizing: border-box;
  gap: 0;
}

/* Match planet-destroyer: grid HUD, pause row 2 right; Rush centered (absolute) */
#hud {
  position: fixed;
  top: 48px;
  left: calc(20px + env(safe-area-inset-left, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  text-align: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  row-gap: 4px;
  align-items: center;
  z-index: 20;
  pointer-events: none;
}

#hud-center {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  pointer-events: none;
}

#hud-lives-spacer {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  min-height: 38px;
  min-width: 38px;
  visibility: hidden;
  pointer-events: none;
}

.qs-hud-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

#pause-wrap {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  align-self: start;
  position: relative;
  pointer-events: auto;
}

#pause-btn {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

#pause-btn:active {
  transform: scale(0.96);
  opacity: 0.92;
}

#pause-btn .icon-play {
  display: none;
}

#pause-btn.is-paused .icon-pause {
  display: none;
}

#pause-btn.is-paused .icon-play {
  display: block;
}

/* Opaque pause veil: hides the board; #hud stays above (z-index 20). */
.qs-pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
  background:
    radial-gradient(ellipse 85% 55% at 50% 42%, rgba(255, 255, 255, 0.07) 0%, transparent 52%),
    linear-gradient(155deg, #0a0614 0%, #071218 48%, #10081c 100%);
  -webkit-backdrop-filter: blur(28px) saturate(0.88);
  backdrop-filter: blur(28px) saturate(0.88);
}

.qs-pause-overlay[hidden] {
  display: none !important;
}

.qs-pause-overlay__text {
  font-family: var(--qs-font-display);
  font-weight: 800;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
}

.qs-challenge {
  flex: 0 1 auto;
  max-width: min(46vw, 200px);
  font-family: var(--qs-font-ui);
  pointer-events: none;
}

/* Rush out of grid flow — centered on #hud width */
#hud .qs-challenge:not(.qs-challenge--hidden) {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  z-index: 21;
}

.qs-challenge--hidden {
  display: none !important;
}

.qs-challenge__inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px 8px;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(30, 27, 50, 0.92), rgba(18, 16, 34, 0.94));
  border: 1px solid rgba(167, 139, 250, 0.35);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 8px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.qs-challenge__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  line-height: 1.1;
}

.qs-challenge__row--title .qs-challenge__label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.qs-challenge__bolt {
  flex-shrink: 0;
  color: #fde68a;
  opacity: 0.95;
  filter: drop-shadow(0 0 6px rgba(250, 204, 21, 0.35));
}

.qs-challenge__label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(196, 181, 253, 0.95);
}

.qs-challenge__remain {
  font-family: var(--qs-font-display);
  font-size: clamp(1rem, 3.2vw, 1.2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fef08a;
  text-shadow: 0 0 12px rgba(250, 204, 21, 0.35);
}

.qs-challenge__timer {
  --qs-ring-pct: 100;
  position: relative;
  margin: 2px auto 0;
  width: clamp(48px, 12vw, 58px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
}

.qs-challenge__ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    conic-gradient(
      from -90deg,
      var(--qs-rush-a) 0 calc(var(--qs-ring-pct) * 1%),
      rgba(255, 255, 255, 0.12) calc(var(--qs-ring-pct) * 1%) 100%
    );
  box-shadow:
    0 0 14px rgba(34, 211, 238, calc(0.35 * var(--qs-glow-strength))),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.qs-challenge__ring::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: inherit;
  background: linear-gradient(145deg, rgba(22, 20, 37, 0.96), rgba(14, 13, 28, 0.98));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.qs-challenge__time {
  position: relative;
  z-index: 1;
  font-family: var(--qs-font-display);
  font-size: clamp(0.92rem, 3.1vw, 1.05rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  text-align: center;
  line-height: 1;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65);
}

.qs-challenge--warn .qs-challenge__inner {
  border-color: rgba(251, 191, 36, 0.45);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 8px 26px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.qs-challenge--warn .qs-challenge__time {
  color: #fde68a;
  animation: qs-rush-pulse 0.9s ease-in-out infinite;
}

.qs-challenge--warn .qs-challenge__ring {
  background:
    conic-gradient(
      from -90deg,
      #fbbf24 0 calc(var(--qs-ring-pct) * 1%),
      rgba(255, 255, 255, 0.12) calc(var(--qs-ring-pct) * 1%) 100%
    );
  box-shadow:
    0 0 15px rgba(251, 191, 36, 0.48),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.qs-challenge--critical .qs-challenge__inner {
  border-color: rgba(248, 113, 113, 0.55);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.4),
    0 0 20px rgba(239, 68, 68, 0.25),
    0 8px 28px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.qs-challenge--critical .qs-challenge__time {
  color: #fecaca;
  animation: qs-rush-pulse 0.45s ease-in-out infinite;
}

.qs-challenge--critical .qs-challenge__ring {
  background:
    conic-gradient(
      from -90deg,
      #fb7185 0 calc(var(--qs-ring-pct) * 1%),
      rgba(255, 255, 255, 0.12) calc(var(--qs-ring-pct) * 1%) 100%
    );
  box-shadow:
    0 0 18px rgba(239, 68, 68, 0.54),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

@keyframes qs-rush-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.03);
    opacity: 0.92;
  }
}

/* Match ball-jump #hud score: large tabular numerals (2.5rem+, scales on wide screens) */
#score-wrap {
  min-width: 6ch;
  font-size: clamp(2.5rem, 7vw, 3.25rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  font-family: var(--qs-font-display);
  letter-spacing: -0.03em;
  line-height: 1;
  transition: transform 0.16s ease, text-shadow 0.16s ease;
}

#score-wrap.qs-score-wrap--live {
  transform: scale(1.03);
  text-shadow: 0 2px 16px rgba(255, 255, 255, calc(0.22 * var(--qs-glow-strength)));
}

#score {
  display: inline-block;
}

.qs-combo {
  font-family: var(--qs-font-display);
  font-size: clamp(0.9rem, 2.8vw, 1.1rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff7ed;
  text-shadow: 0 0 14px rgba(249, 115, 22, calc(0.35 * var(--qs-glow-strength)));
  background: linear-gradient(145deg, rgba(249, 115, 22, 0.78), rgba(234, 88, 12, 0.68));
  border: 1px solid rgba(255, 237, 213, 0.45);
  border-radius: 999px;
  padding: 2px 9px 3px;
  line-height: 1.1;
  transform-origin: 100% 50%;
  will-change: transform, opacity;
}

.qs-combo--hidden {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.qs-combo--bump {
  animation: qs-combo-bump 0.36s cubic-bezier(0.2, 0.85, 0.2, 1.2);
}

@keyframes qs-combo-bump {
  0% {
    transform: scale(0.78);
  }
  55% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

.qs-moment {
  position: fixed;
  left: 50%;
  top: clamp(64px, 12vh, 110px);
  transform: translateX(-50%) scale(0.9);
  z-index: 30;
  font-family: var(--qs-font-display);
  font-size: clamp(1rem, 3.6vw, 1.5rem);
  font-weight: 900;
  letter-spacing: 0.14em;
  padding: 6px 14px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.qs-moment--hidden {
  opacity: 0;
}

.qs-moment--show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.qs-moment--nice {
  color: #ecfeff;
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.9), rgba(59, 130, 246, 0.82));
}

.qs-moment--great {
  color: #fffbeb;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.9), rgba(249, 115, 22, 0.84));
}

.qs-moment--insane {
  color: #fff1f2;
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.9), rgba(190, 24, 93, 0.85));
}

.qs-board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  margin-top: clamp(24px, 5.6dvh, 52px);
}

#qs-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(9px, 2.2vmin, 14px);
  width: min(98vw, calc((100dvh - 170px) / 1.28), 620px);
  max-width: 620px;
  aspect-ratio: 1 / 1.28;
  min-height: 0;
  background:
    linear-gradient(var(--qs-grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--qs-grid-line) 1px, transparent 1px),
    linear-gradient(145deg, rgba(38, 38, 62, 0.97), rgba(22, 22, 40, 0.94));
  background-size:
    33.333% 33.333%,
    33.333% 33.333%,
    auto;
  border-radius: 22px;
  padding: clamp(11px, 2.8vmin, 16px);
  box-sizing: border-box;
  align-content: stretch;
  border: 1px solid rgba(255, 255, 255, 0.12);
  position: relative;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.4),
    0 14px 44px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -2px 12px rgba(0, 0, 0, 0.2);
}

#qs-grid::after {
  content: "";
  position: absolute;
  inset: -12%;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(255, 255, 255, calc(0.08 * var(--qs-glow-strength))) 42%,
    rgba(255, 255, 255, calc(0.24 * var(--qs-glow-strength) * var(--qs-sweep-strength, 1))) 50%,
    rgba(255, 255, 255, calc(0.08 * var(--qs-glow-strength))) 58%,
    transparent 100%
  );
  transform: translateX(-120%) skewX(-16deg);
}

#qs-grid.qs-grid--sweep::after {
  animation: qs-grid-sweep 0.54s cubic-bezier(0.22, 0.7, 0.2, 1) forwards;
}

@keyframes qs-grid-sweep {
  0% {
    transform: translateX(-120%) skewX(-16deg);
    opacity: 0;
  }
  18% {
    opacity: calc(0.75 * var(--qs-fx-intensity));
  }
  100% {
    transform: translateX(120%) skewX(-16deg);
    opacity: 0;
  }
}

/* WebKit: flex column fills the grid cell */
#qs-grid .qs-cell {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 5px;
  min-height: 0;
  min-width: 0;
  align-self: stretch;
  justify-self: stretch;
}

.qs-cell {
  background: rgba(0, 0, 0, 0.26);
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.08);
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 5px;
  min-height: 0;
  min-width: 0;
  align-self: stretch;
  justify-self: stretch;
  cursor: grab;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow:
    inset 0 3px 12px rgba(0, 0, 0, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 1px 0 rgba(255, 255, 255, 0.04);
}

/* Empty tray — class toggled in render (avoids :has() in old WebViews) */
.qs-cell--empty {
  background:
    radial-gradient(ellipse 90% 80% at 50% 100%, rgba(255, 255, 255, 0.04), transparent 55%),
    rgba(0, 0, 0, 0.18);
}

.qs-cell--empty .qs-stack::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  height: 22%;
  transform: translate(-50%, -40%);
  border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  pointer-events: none;
  opacity: 0.85;
}

.qs-cell:active {
  cursor: grabbing;
}

.qs-cell--drag-source {
  border-color: #a78bfa;
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.35),
    0 0 0 2px rgba(124, 58, 237, 0.5);
  z-index: 1;
}

.qs-cell--drop-ok {
  border-color: var(--qs-drop-ok);
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.25),
    0 0 0 3px rgba(var(--qs-drop-ok-rgb), 0.58);
}

.qs-cell--drop-bad {
  border-color: var(--qs-danger);
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.25),
    0 0 0 3px rgba(var(--qs-danger-rgb), 0.45);
}

.qs-cell--reject {
  animation: qs-reject-shake 0.28s ease-out;
}

.qs-cell--junk-spawn {
  animation: qs-junk-flash 0.42s ease-out;
}

@keyframes qs-reject-shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes qs-junk-flash {
  0% {
    border-color: rgba(148, 163, 184, 0.18);
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.35),
      0 0 0 0 rgba(148, 163, 184, 0);
  }
  45% {
    border-color: rgba(203, 213, 225, 0.9);
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.24),
      0 0 0 3px rgba(148, 163, 184, 0.48),
      0 0 22px rgba(148, 163, 184, 0.34);
  }
  100% {
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.35),
      0 0 0 0 rgba(148, 163, 184, 0);
  }
}

.qs-cell--hint-ok:not(.qs-cell--drop-ok):not(.qs-cell--drop-bad) {
  border-color: rgba(var(--qs-drop-ok-rgb), 0.5);
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.35),
    0 0 12px rgba(var(--qs-drop-ok-rgb), 0.28);
  animation: qs-hint-pulse 1.1s ease-in-out infinite;
}

@keyframes qs-hint-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}

.qs-cell--clear-burst {
  animation: qs-clear-burst 0.52s ease-out forwards;
  z-index: 2;
}

.qs-cell--drop-snap {
  animation: qs-drop-snap 0.24s cubic-bezier(0.2, 0.92, 0.3, 1);
}

@keyframes qs-drop-snap {
  0% {
    transform: scale(0.97);
    filter: brightness(0.96);
  }
  55% {
    transform: scale(1.025);
    filter: brightness(1.12);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

.qs-cell--combo {
  animation: qs-combo-cell 0.38s ease-out;
}

@keyframes qs-combo-cell {
  0% {
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.35),
      0 0 0 0 rgba(var(--qs-combo-rgb), 0);
  }
  38% {
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.2),
      0 0 0 3px rgba(var(--qs-combo-rgb), 0.48),
      0 0 18px rgba(var(--qs-combo-rgb), 0.34);
  }
  100% {
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.35),
      0 0 0 0 rgba(var(--qs-combo-rgb), 0);
  }
}

@keyframes qs-clear-burst {
  0% {
    filter: brightness(1) saturate(1);
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.35),
      0 0 0 0 rgba(255, 255, 255, 0);
  }
  35% {
    filter: brightness(1.35) saturate(1.2);
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.2),
      0 0 28px rgba(255, 255, 255, 0.45);
  }
  100% {
    filter: brightness(1) saturate(1);
    box-shadow:
      inset 0 3px 10px rgba(0, 0, 0, 0.35),
      0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.qs-cell--lifting .qs-piece:last-child {
  opacity: 0.28;
  transform: scale(0.96);
}

.qs-stack {
  position: relative;
  flex: 1 1 0%;
  width: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 3px;
  align-content: stretch;
  box-sizing: border-box;
  pointer-events: auto;
  isolation: isolate;
}

.qs-piece {
  pointer-events: auto;
  min-height: 0;
  min-width: 0;
  max-height: none;
  box-sizing: border-box;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--qs-font-display);
  font-weight: 800;
  font-size: clamp(14px, 4.8vmin, 23px);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 2px 6px rgba(0, 0, 0, 0.25);
  background: linear-gradient(180deg, var(--qs-p-top), var(--qs-p-bot));
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.qs-piece::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 255, 255, 0.05) 40%,
    transparent 65%
  );
  pointer-events: none;
  z-index: 0;
}

.qs-piece--junk {
  border-style: dashed;
  border-color: rgba(226, 232, 240, 0.72);
  color: #f8fafc;
}

.qs-piece--junk::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.18) 0 7px,
      rgba(255, 255, 255, 0) 7px 14px
    ),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(15, 23, 42, 0.12));
  pointer-events: none;
  z-index: 0;
}

.qs-piece--junk .qs-piece-label {
  letter-spacing: 0.16em;
}

.qs-piece-label {
  position: relative;
  z-index: 1;
}

/* depth-0 = top of stack (items[0]), depth-2 = bottom — push bottom “into” tray */
.qs-piece--depth-0 {
  z-index: 3;
  transform: translateY(0);
  filter: brightness(1) saturate(1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 4px 10px rgba(0, 0, 0, 0.35),
    0 1px 0 rgba(255, 255, 255, 0.08);
}

.qs-piece--depth-1 {
  z-index: 2;
  transform: translateY(2px) scale(0.992);
  filter: brightness(0.94) saturate(0.98);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 3px 7px rgba(0, 0, 0, 0.32);
}

.qs-piece--depth-2 {
  z-index: 1;
  transform: translateY(4px) scale(0.985);
  filter: brightness(0.88) saturate(0.95);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -2px 0 rgba(0, 0, 0, 0.28),
    0 2px 5px rgba(0, 0, 0, 0.38);
}

.qs-drag-ghost {
  opacity: calc(0.23 * var(--qs-fx-intensity));
  filter: saturate(0.9) blur(0.2px);
}

.qs-drag-ghost canvas {
  opacity: inherit;
}

.qs-score-float {
  position: fixed;
  font-family: var(--qs-font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 4.5vw, 2rem);
  color: #4ade80;
  text-shadow: 0 0 12px rgba(74, 222, 128, 0.5);
  pointer-events: none;
  z-index: 10000;
  animation: qs-float-up 0.85s ease-out forwards;
}

@keyframes qs-float-up {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-36px) scale(1.05);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --qs-fx-intensity: 0.35;
    --qs-glow-strength: 0.6;
  }

  .qs-atmosphere::before {
    animation: none;
  }

  .qs-cell--hint-ok:not(.qs-cell--drop-ok):not(.qs-cell--drop-bad) {
    animation: none;
  }

  .qs-cell--clear-burst {
    animation: none;
  }

  .qs-cell--reject {
    animation: none;
  }

  .qs-cell--junk-spawn {
    animation: none;
  }

  .qs-challenge--warn .qs-challenge__time,
  .qs-challenge--critical .qs-challenge__time {
    animation: none;
  }

  .qs-score-float {
    animation: qs-float-up-static 0.85s ease-out forwards;
  }

  .qs-piece {
    transition: none;
  }

  .qs-cell--drop-snap,
  .qs-cell--combo,
  #qs-grid.qs-grid--sweep::after,
  .qs-combo--bump {
    animation: none;
  }

  .qs-moment {
    transition: none;
  }

  .qs-drag-ghost {
    display: none !important;
  }
}

@keyframes qs-float-up-static {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (hover: none) and (pointer: coarse) {
  :root {
    --qs-fx-intensity: 0.85;
    --qs-glow-strength: 0.85;
  }
}

@media (max-height: 860px) {
  .qs-board-wrap {
    margin-top: clamp(14px, 4dvh, 30px);
  }

  #qs-grid {
    width: min(98vw, calc((100dvh - 148px) / 1.22), 580px);
    max-width: 580px;
    aspect-ratio: 1 / 1.22;
    padding: clamp(10px, 2.4vmin, 14px);
  }

  .qs-piece {
    font-size: clamp(13px, 4.2vmin, 20px);
  }

  #score-wrap {
    font-size: clamp(2.2rem, 6.2vw, 2.9rem);
  }

  .qs-challenge {
    max-width: min(42vw, 184px);
  }
}

@media (max-height: 760px) {
  .qs-board-wrap {
    margin-top: clamp(10px, 2.2dvh, 20px);
  }

  #qs-grid {
    width: min(98vw, calc((100dvh - 132px) / 1.16), 540px);
    max-width: 540px;
    aspect-ratio: 1 / 1.16;
    gap: clamp(8px, 2vmin, 12px);
    padding: clamp(9px, 2.1vmin, 12px);
  }

  .qs-piece {
    font-size: clamp(12px, 3.8vmin, 18px);
    border-radius: 9px;
  }

  .qs-stack {
    gap: 2px;
  }

  .qs-challenge {
    max-width: min(40vw, 170px);
  }
}
