:root {
  --ink: #FFF7EE;
  --dim: #D7C2E8;
  --coral: #FF5D6C;
  --mint: #2EE0C5;
  --sun: #FFC93C;
  --grape: #9B6BFF;
  --sky: #4EA2FF;
  --good: #3DFFB0;
  --bad: #FF4D6A;
  --ad: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Nunito, "Apple SD Gothic Neo", sans-serif;
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: #1A1030;
}

.hide { display: none !important; }

#sky {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(18, 8, 36, 0.18), rgba(18, 8, 36, 0.42)),
    url("art/bg.jpg") center/cover no-repeat;
  z-index: 0;
}
#sky::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(70% 50% at 50% 42%, rgba(255, 140, 90, 0.08), transparent 70%);
}

#app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto var(--ad);
  padding:
    calc(8px + var(--safe-t))
    16px
    calc(8px + var(--safe-b))
    16px;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: Fredoka, Nunito, sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.03em;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
.brand img {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.28), 0 10px 20px rgba(0,0,0,0.2);
}
.chips { display: flex; align-items: center; gap: 6px; }
.chip {
  min-width: 58px;
  padding: 5px 8px 4px;
  border-radius: 14px;
  text-align: center;
  background: rgba(20, 8, 36, 0.42);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
}
.chip small {
  display: block;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--dim);
  font-weight: 800;
}
.chip b {
  font-family: Fredoka, Nunito, sans-serif;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hero {
  text-align: center;
  margin-top: 2px;
}
.hero small {
  display: block;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: #FFD7A8;
  font-weight: 800;
}
.hero b {
  display: block;
  font-family: Fredoka, Nunito, sans-serif;
  font-size: 58px;
  line-height: 0.9;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #FFF8EA 20%, #FFD27A 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(80, 20, 10, 0.35));
}
.hero em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: 13px;
  font-weight: 800;
  color: #E8C9FF;
}

#mute {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: rgba(20, 8, 36, 0.42);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.14);
  cursor: pointer;
  display: grid;
  place-items: center;
}
#mute:active { transform: translateY(1px); }
#mute svg { fill: currentColor; }

#hint {
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: #FFE7C2;
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(148px + var(--safe-t));
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.35);
  z-index: 2;
  transition: opacity 180ms ease;
}
#hint.gone { opacity: 0; }

#combo {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, 0);
  z-index: 20;
  pointer-events: none;
  font-family: Fredoka, Nunito, sans-serif;
  font-size: 38px;
  font-weight: 700;
  color: #fff;
  padding: 6px 22px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #FFB347, #FF5A36);
  box-shadow: 0 7px 0 #B83314, 0 14px 28px rgba(0,0,0,0.28);
  opacity: 0;
}
#combo.show { animation: popin 520ms cubic-bezier(0.16, 1.2, 0.3, 1) forwards; }
@keyframes popin {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(0.6); }
  35% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(1); }
}

#stage {
  display: grid;
  place-items: center;
  min-height: 0;
}
#board {
  --cell: 38px;
  --gap: 3px;
  --pad: 12px;
  width: calc(var(--cell) * 8 + var(--gap) * 7 + var(--pad) * 2);
  height: calc(var(--cell) * 8 + var(--gap) * 7 + var(--pad) * 2);
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  gap: var(--gap);
  padding: var(--pad);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 28%),
    linear-gradient(180deg, #3A215C, #231338);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.22),
    inset 0 -10px 18px rgba(0,0,0,0.28),
    0 0 0 3px rgba(255, 206, 120, 0.22),
    0 14px 0 #14081F,
    0 28px 40px rgba(0,0,0,0.35);
  transition: transform 80ms ease;
}
#board.shake { animation: shake 280ms ease; }
@keyframes shake {
  20% { transform: translateX(-4px) rotate(-0.4deg); }
  40% { transform: translateX(4px) rotate(0.4deg); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 11px;
  background: linear-gradient(180deg, #1A0E2C, #2A1644);
  box-shadow:
    inset 0 3px 5px rgba(0,0,0,0.45),
    inset 0 -1px 0 rgba(255,255,255,0.05);
  position: relative;
}
.cell.on { background: transparent; box-shadow: none; }
.cell.ghost-ok { box-shadow: inset 0 0 0 2px var(--good), inset 0 3px 5px rgba(0,0,0,0.35); }
.cell.ghost-bad { box-shadow: inset 0 0 0 2px var(--bad), inset 0 3px 5px rgba(0,0,0,0.35); }
.cell.pop .block { animation: cellpop 300ms ease-out forwards; }
@keyframes cellpop {
  40% { transform: scale(1.18) rotate(-4deg); }
  100% { transform: scale(0.15); opacity: 0; }
}

.block, #ghost i, .mini i.cube {
  display: block;
  border-radius: 28%;
  position: relative;
  background:
    radial-gradient(120% 80% at 28% 18%, rgba(255,255,255,0.78) 0 8%, rgba(255,255,255,0) 36%),
    linear-gradient(180deg, var(--hi), var(--mid) 58%, var(--lo));
  box-shadow:
    inset 0 -7px 8px rgba(0,0,0,0.22),
    inset 0 2px 0 rgba(255,255,255,0.38),
    0 4px 0 var(--edge),
    0 8px 12px rgba(0,0,0,0.28);
}
.block {
  position: absolute;
  inset: 1px;
}
.block.c0, .mini i.c0, #ghost i.c0 { --hi:#FF9AA4; --mid:#FF5D6C; --lo:#D12E4A; --edge:#9A1630; }
.block.c1, .mini i.c1, #ghost i.c1 { --hi:#8CFFE8; --mid:#2EE0C5; --lo:#0FA58E; --edge:#067A68; }
.block.c2, .mini i.c2, #ghost i.c2 { --hi:#FFE38A; --mid:#FFC93C; --lo:#E09A00; --edge:#A66A00; }
.block.c3, .mini i.c3, #ghost i.c3 { --hi:#C9B0FF; --mid:#9B6BFF; --lo:#6A36D6; --edge:#471B9A; }
.block.c4, .mini i.c4, #ghost i.c4 { --hi:#9CCCFF; --mid:#4EA2FF; --lo:#1B6FD4; --edge:#0D4A96; }
.block.drop { animation: dropin 180ms cubic-bezier(0.2, 1.4, 0.3, 1); }
@keyframes dropin {
  from { transform: scale(1.18); }
  to { transform: scale(1); }
}

#tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  min-height: 104px;
}
.piece {
  height: 104px;
  border: 0;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 40%),
    rgba(18, 8, 34, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.16),
    0 8px 0 rgba(8, 2, 16, 0.45);
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
  position: relative;
}
.piece:active { cursor: grabbing; }
.piece.used {
  opacity: 0.22;
  pointer-events: none;
  box-shadow: none;
}
.piece.lift { opacity: 0.18; }
.mini {
  display: grid;
  gap: 3px;
  pointer-events: none;
}
.mini i {
  width: 18px;
  height: 18px;
}
.mini i.cube { border-radius: 6px; box-shadow: inset 0 -3px 4px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.4), 0 2px 0 var(--edge); }

#adbar {
  height: var(--ad);
  border-radius: 16px;
  background: rgba(10, 4, 20, 0.35);
  border: 1px dashed rgba(255,255,255,0.16);
  display: grid;
  place-items: center;
  color: rgba(255,255,255,0.38);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  overflow: hidden;
}
#adbar.live { background: #fff; color: transparent; border: 0; }

#ghost {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 30;
  display: none;
  filter: drop-shadow(0 10px 12px rgba(0,0,0,0.35));
}
#ghost.on { display: block; }
#ghost i { position: absolute; }

#over {
  position: fixed;
  inset: 0;
  background: rgba(10, 4, 22, 0.55);
  display: grid;
  place-items: end center;
  z-index: 40;
  padding: 16px 16px calc(16px + var(--safe-b));
  backdrop-filter: blur(8px);
}
#over .sheet {
  width: min(420px, 100%);
  background:
    linear-gradient(180deg, #4A2A78, #2A1548);
  border-radius: 30px 30px 24px 24px;
  padding: 24px 20px 18px;
  text-align: center;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 -12px 40px rgba(0,0,0,0.28);
  animation: up 240ms ease-out;
}
@keyframes up {
  from { transform: translateY(28px); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}
.kicker {
  margin: 0;
  color: #FFD7A8;
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 12px;
}
#over-title {
  margin: 4px 0 16px;
  font-family: Fredoka, Nunito, sans-serif;
  font-size: 64px;
  line-height: 0.9;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #FFF8EA, #FFD27A);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.recap {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.recap li {
  background: rgba(10, 4, 22, 0.28);
  border-radius: 16px;
  padding: 9px 4px;
  border: 1px solid rgba(255,255,255,0.08);
}
.recap span { display: block; font-size: 11px; color: var(--dim); font-weight: 800; }
.recap b { font-size: 16px; font-family: Fredoka, Nunito, sans-serif; }
.go {
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, #FFB347, #FF5A36);
  color: #fff;
  font: 700 24px/1 Fredoka, Nunito, sans-serif;
  box-shadow: 0 7px 0 #B83314;
  cursor: pointer;
}
.go:active { transform: translateY(4px); box-shadow: 0 3px 0 #B83314; }

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 25; }
.float {
  position: absolute;
  font-family: Fredoka, Nunito, sans-serif;
  font-weight: 700;
  font-size: 28px;
  color: #FFE38A;
  text-shadow: 0 3px 0 #9A4A00;
  animation: float 780ms ease-out forwards;
}
@keyframes float {
  to { transform: translateY(-36px); opacity: 0; }
}
.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: spark 520ms ease-out forwards;
}
@keyframes spark {
  to { transform: translate(var(--x), var(--y)) scale(0.2); opacity: 0; }
}

@media (max-height: 700px) {
  .hero b { font-size: 44px; }
  #tray { min-height: 88px; }
  .piece { height: 88px; }
}
@media (prefers-reduced-motion: reduce) {
  #combo.show, .cell.pop .block, #over .sheet, .float, .spark, #board.shake, .block.drop { animation: none; }
}
button:focus-visible { outline: 3px solid #FFB347; outline-offset: 2px; }
