:root {
  color-scheme: dark;
  --bg: #10131a;
  --panel: #171b24;
  --cell: #222835;
  --cell-line: #303746;
  --text: #eef3f8;
  --muted: #98a3b3;
  --accent: #48c6a8;
  --bad: #ff6b6b;
  --shadow: rgba(0, 0, 0, .28);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(72, 198, 168, .12), transparent 30rem),
    linear-gradient(145deg, #10131a 0%, #171c25 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  font: inherit;
}

.shell {
  min-height: 100dvh;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(.75rem, env(safe-area-inset-top)) .85rem max(.85rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: .75rem;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .6rem;
}

.icon-button,
#play-again {
  min-height: 2.75rem;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 8px;
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .45rem;
}

.version-pill {
  min-height: 2.75rem;
  min-width: 4.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 .6rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .11);
  background: rgba(255, 255, 255, .07);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
}

.version-pill[hidden] {
  display: none;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  font-size: 1.35rem;
  line-height: 1;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}

.score-box {
  min-width: 0;
  padding: .45rem .65rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  text-align: center;
  box-shadow: 0 8px 22px var(--shadow);
}

.score-box span {
  display: block;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.score-box strong {
  display: block;
  margin-top: .08rem;
  font-size: clamp(1.12rem, 4.2vw, 1.8rem);
  line-height: 1;
}

.game-area {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  gap: .8rem;
}

.board-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.board {
  --board-size: min(92vw, 86dvh - 12rem, 560px);
  width: var(--board-size);
  height: var(--board-size);
  padding: clamp(.35rem, 1.7vw, .55rem);
  border-radius: 8px;
  background: linear-gradient(180deg, #1a202b, #151922);
  border: 1px solid rgba(255, 255, 255, .1);
  box-shadow: 0 16px 45px rgba(0, 0, 0, .32);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: clamp(.22rem, 1vw, .42rem);
  touch-action: none;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  background: var(--cell);
  border: 1px solid var(--cell-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
  overflow: hidden;
}

.cell.filled {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, .28) 0%, rgba(255, 255, 255, .08) 32%, rgba(0, 0, 0, .12) 68%, rgba(0, 0, 0, .28) 100%),
    var(--block-color);
  border-color: rgba(255, 255, 255, .2);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .38),
    inset 2px 0 0 rgba(255, 255, 255, .14),
    inset -3px -5px 0 rgba(0, 0, 0, .24),
    0 5px 10px rgba(0, 0, 0, .22);
}

.cell.filled::before,
.cell.preview::before,
.mini-cell.on::before {
  content: "";
  position: absolute;
  inset: 12% 14% auto 14%;
  height: 22%;
  border-radius: 999px;
  background: rgba(255, 255, 255, .24);
  filter: blur(.5px);
}

.cell.filled::after,
.cell.preview::after,
.mini-cell.on::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 48%;
  height: 48%;
  background: linear-gradient(135deg, transparent 12%, rgba(0, 0, 0, .18));
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.cell.preview {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, .34), rgba(0, 0, 0, .18)),
    var(--block-color);
  border-color: rgba(255, 255, 255, .44);
  opacity: .82;
}

.cell.will-clear {
  border-color: rgba(255, 236, 138, .95);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .42),
    inset -3px -5px 0 rgba(0, 0, 0, .22),
    0 0 0 2px rgba(255, 236, 138, .35),
    0 0 18px rgba(255, 220, 80, .56);
  animation: clearHint .7s ease-in-out infinite alternate;
  z-index: 2;
}

.cell.clearing {
  --clear-delay: 0ms;
  z-index: 4;
  border-color: rgba(255, 244, 168, .9);
  animation: blast var(--clear-duration, 360ms) cubic-bezier(.2, .9, .2, 1) var(--clear-delay) forwards;
}

.cell.clearing::before {
  content: "";
  position: absolute;
  inset: -38%;
  height: auto;
  border-radius: 0;
  background:
    radial-gradient(circle, rgba(255, 255, 255, .96) 0 8%, rgba(255, 244, 168, .75) 9% 22%, transparent 48%),
    linear-gradient(90deg, transparent 0 18%, rgba(255, 255, 255, .95) 46% 54%, transparent 82% 100%);
  filter: blur(.4px);
  opacity: 0;
  transform: scale(.42) rotate(12deg);
  animation: clearSweep var(--clear-duration, 360ms) ease-out var(--clear-delay) forwards;
}

.cell.clearing::after {
  content: "";
  position: absolute;
  inset: -2px;
  width: auto;
  height: auto;
  background: linear-gradient(135deg, transparent 10%, rgba(255, 255, 255, .38), transparent 74%);
  clip-path: none;
  opacity: 0;
  animation: clearShine var(--clear-duration, 360ms) ease-out var(--clear-delay) forwards;
}

.cell.clearing-row {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .48),
    inset -3px -5px 0 rgba(0, 0, 0, .18),
    0 0 0 2px rgba(255, 244, 168, .42),
    0 0 18px rgba(255, 236, 138, .62);
}

.cell.clearing-col {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .48),
    inset -3px -5px 0 rgba(0, 0, 0, .18),
    0 0 0 2px rgba(72, 198, 168, .4),
    0 0 18px rgba(72, 198, 168, .62);
}

.tray {
  min-height: 7.1rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .65rem;
}

.piece-slot {
  min-width: 0;
  min-height: 7.1rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, .055);
  border: 1px solid rgba(255, 255, 255, .08);
  touch-action: none;
}

.piece-slot:not(.empty) {
  cursor: grab;
}

.piece-slot.empty {
  opacity: .28;
}

.piece {
  --unit: clamp(.72rem, 5.1vw, 1.72rem);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--unit));
  grid-template-rows: repeat(var(--rows), var(--unit));
  gap: calc(var(--unit) * .16);
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .25));
}

.piece:active,
.piece.selected {
  cursor: grabbing;
  transform: translateY(-2px) scale(1.04);
}

.mini-cell {
  position: relative;
  width: var(--unit);
  height: var(--unit);
  border-radius: 5px;
  overflow: hidden;
}

.mini-cell.on {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, .28) 0%, rgba(255, 255, 255, .08) 34%, rgba(0, 0, 0, .25) 100%),
    var(--block-color);
  border: 1px solid rgba(255, 255, 255, .22);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .34),
    inset 2px 0 0 rgba(255, 255, 255, .12),
    inset -3px -4px 0 rgba(0, 0, 0, .22),
    0 5px 9px rgba(0, 0, 0, .22);
}

.drag-piece {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  opacity: .92;
  transform: translate(-50%, -128%) scale(1.12);
}

.clear-burst {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 8px 20px rgba(0, 0, 0, .45);
}

.clear-burst[hidden] {
  display: none;
}

.clear-burst strong,
.clear-burst span {
  grid-area: 1 / 1;
}

.clear-burst strong {
  color: #fff4a8;
  font-size: clamp(4.4rem, 18vw, 9rem);
  font-weight: 1000;
  line-height: .9;
  transform: translateY(-.28em);
  animation: clearText .92s ease-out forwards;
}

.clear-burst span {
  color: #48c6a8;
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  font-weight: 1000;
  transform: translateY(2.55em);
  animation: bonusText .92s ease-out forwards;
}

.message {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(10, 13, 18, .72);
  backdrop-filter: blur(7px);
}

.message[hidden] {
  display: none;
}

.message-panel {
  width: min(100%, 320px);
  padding: 1.25rem;
  border-radius: 8px;
  background: #171b24;
  border: 1px solid rgba(255, 255, 255, .12);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}

.message-panel h1 {
  margin: 0;
  font-size: 1.8rem;
}

.message-panel p {
  margin: .45rem 0 1rem;
  color: var(--muted);
  font-weight: 700;
}

#play-again {
  width: 100%;
  background: var(--accent);
  color: #07100d;
  border-color: transparent;
  font-weight: 900;
}

@keyframes clearHint {
  from {
    filter: brightness(1);
  }

  to {
    filter: brightness(1.28);
  }
}

@keyframes blast {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  38% {
    transform: scale(var(--clear-scale, 1.45)) rotate(3deg);
    opacity: 1;
    filter: brightness(1.55);
  }

  100% {
    transform: scale(.12) rotate(-8deg);
    opacity: 0;
    filter: brightness(1.9);
  }
}

@keyframes clearSweep {
  0% {
    opacity: 0;
    transform: scale(.42) rotate(12deg);
  }

  26% {
    opacity: 1;
    transform: scale(.9) rotate(12deg);
  }

  58% {
    opacity: .95;
    transform: scale(1.38) rotate(12deg);
  }

  100% {
    opacity: 0;
    transform: scale(1.9) rotate(12deg);
  }
}

@keyframes clearShine {
  0% {
    opacity: 0;
    transform: translateX(-70%) translateY(-70%);
  }

  30% {
    opacity: .95;
  }

  100% {
    opacity: 0;
    transform: translateX(70%) translateY(70%);
  }
}

@keyframes clearText {
  0% {
    opacity: 0;
    transform: translateY(-.28em) scale(.5);
  }

  30% {
    opacity: 1;
    transform: translateY(-.28em) scale(var(--burst-scale, 1.25));
  }

  60% {
    opacity: 1;
    transform: translateY(-.28em) scale(calc(var(--burst-scale, 1.25) * .92));
  }

  100% {
    opacity: 0;
    transform: translateY(-.28em) scale(calc(var(--burst-scale, 1.25) * 1.16));
  }
}

@keyframes bonusText {
  0% {
    opacity: 0;
    transform: translateY(2.55em) scale(.6);
  }

  28%,
  72% {
    opacity: 1;
    transform: translateY(2.55em) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(2.55em) scale(1.18);
  }
}

@keyframes pop {
  50% {
    transform: scale(.78);
    opacity: .65;
  }
}

@media (max-width: 430px) {
  .shell {
    padding-left: .55rem;
    padding-right: .55rem;
    gap: .55rem;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .45rem;
  }

  .icon-button,
  .version-pill {
    min-height: 2.45rem;
  }

  .version-pill {
    min-width: 3.75rem;
    padding: 0 .45rem;
    font-size: .7rem;
  }

  .score-box {
    padding: .38rem .45rem;
  }

  .tray {
    min-height: 6.4rem;
    gap: .45rem;
  }

  .piece-slot {
    min-height: 6.4rem;
  }
}
