/* ============ Block Drop ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --cell: 44px;            /* set by JS */
  --bg-top: #4a7ce0;
  --bg-bottom: #2c4fb4;
  --board-bg: #17224d;
  --cell-bg: #1c2a5c;
  --cell-line: rgba(255,255,255,0.05);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body {
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: #fff;
}

#app {
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  position: relative;
}

/* ---------- top bar ---------- */
#topbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px 0;
}

#best-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 26px;
  font-weight: 700;
  color: #ffb300;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
#crown { width: 38px; height: 29px; filter: drop-shadow(0 2px 1px rgba(0,0,0,0.3)); }

#settings-btn {
  background: none;
  border: none;
  color: #b9c6ea;
  width: 40px; height: 40px;
  cursor: pointer;
  opacity: 0.9;
}
#settings-btn:active { transform: rotate(30deg) scale(0.92); }
#settings-btn svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 1px rgba(0,0,0,0.25)); }

/* ---------- score ---------- */
#score-wrap {
  position: relative;
  margin: 4px 0 10px;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#score {
  font-size: 62px;
  font-weight: 700;
  text-shadow: 0 3px 0 rgba(0,0,0,0.28);
  position: relative;
  z-index: 1;
}
#score-gem {
  position: absolute;
  left: 50%; top: 50%;
  width: 84px; height: 84px;
  transform: translate(-50%,-54%) rotate(45deg) scale(0);
  background: linear-gradient(135deg, #62c8ff, #2f6df6);
  border-radius: 16px;
  opacity: 0;
  transition: transform 0.35s cubic-bezier(.2,1.6,.4,1), opacity 0.3s;
}
#app.streak #score-gem { transform: translate(-50%,-54%) rotate(45deg) scale(1); opacity: 0.85; }

/* ---------- board ---------- */
#board-wrap { position: relative; }

#board {
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  background: var(--board-bg);
  padding: 4px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,20,0.35), inset 0 0 0 2px rgba(0,0,0,0.25);
  transition: box-shadow 0.4s;
}
/* combo streak glow */
#app.streak #board {
  box-shadow: 0 8px 24px rgba(0,0,20,0.35), 0 0 0 3px rgba(120,255,140,0.55), 0 0 22px 6px rgba(120,255,160,0.45);
  animation: streak-pulse 1.1s ease-in-out infinite;
}
@keyframes streak-pulse {
  50% { box-shadow: 0 8px 24px rgba(0,0,20,0.35), 0 0 0 3px rgba(160,255,180,0.9), 0 0 30px 10px rgba(120,255,160,0.65); }
}

.cell {
  width: var(--cell);
  height: var(--cell);
  background: var(--cell-bg);
  box-shadow: inset 0 0 0 1px var(--cell-line);
  position: relative;
}

/* ---------- blocks ---------- */
.block {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--cell) * 0.1);
  box-shadow:
    inset 0 calc(var(--cell) * 0.12) 0 rgba(255,255,255,0.4),
    inset 0 calc(var(--cell) * -0.14) 0 rgba(0,0,0,0.32),
    inset calc(var(--cell) * 0.1) 0 0 rgba(255,255,255,0.14),
    inset calc(var(--cell) * -0.1) 0 0 rgba(0,0,0,0.16);
}
.block::after { /* gloss dot */
  content: "";
  position: absolute;
  left: 16%; top: 12%;
  width: 26%; height: 16%;
  border-radius: 50%;
  background: rgba(255,255,255,0.5);
  filter: blur(1px);
}

.c0 { background: #ef4136; }  /* red */
.c1 { background: #f7941d; }  /* orange */
.c2 { background: #ffb300; }  /* amber */
.c3 { background: #3fc437; }  /* green */
.c4 { background: #29c5f6; }  /* cyan */
.c5 { background: #2f6df6; }  /* blue */
.c6 { background: #a24bf3; }  /* purple */

.cell .block.placed { animation: pop-in 0.18s cubic-bezier(.2,1.8,.4,1); }
@keyframes pop-in { 0% { transform: scale(0.6); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* ghost preview */
.cell .block.ghost { opacity: 0.35; }
.cell .block.ghost::after { display: none; }

/* line about to clear */
.cell.will-clear .block { animation: will-glow 0.5s ease-in-out infinite; }
@keyframes will-glow {
  0%, 100% { filter: brightness(1.35) saturate(1.2); }
  50% { filter: brightness(1.9) saturate(0.7); }
}

/* clearing */
.cell .block.clearing {
  animation: clear-pop 0.3s ease-in forwards;
  z-index: 2;
}
@keyframes clear-pop {
  0%   { transform: scale(1);   filter: brightness(2); }
  100% { transform: scale(0);   filter: brightness(3); opacity: 0; }
}

/* particles */
.spark {
  position: absolute;
  width: 7px; height: 7px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 5;
  transition: transform 0.55s cubic-bezier(.1,.7,.4,1), opacity 0.55s;
}

/* score popups */
.popup {
  position: absolute;
  z-index: 6;
  font-size: 30px;
  font-weight: 700;
  color: #ffd75e;
  text-shadow: 0 2px 0 rgba(160,80,0,0.6), 0 0 12px rgba(255,200,60,0.7);
  pointer-events: none;
  transform: translate(-50%,-50%);
  animation: pop-float 0.9s ease-out forwards;
  white-space: nowrap;
}
@keyframes pop-float {
  0%   { opacity: 0; transform: translate(-50%,-30%) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%,-50%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%,-150%) scale(1); }
}

/* praise text */
#praise {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%,-50%);
  z-index: 7;
  pointer-events: none;
  font-size: 46px;
  font-weight: 700;
  font-style: italic;
  white-space: nowrap;
  opacity: 0;
  background: linear-gradient(180deg, #fff, #9fd4ff 60%, #58a9ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(20,60,160,0.55)) drop-shadow(0 0 14px rgba(120,190,255,0.6));
}
#praise.show { animation: praise-pop 1s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes praise-pop {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(0.4); }
  18%  { opacity: 1; transform: translate(-50%,-50%) scale(1.12); }
  30%  { transform: translate(-50%,-50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-70%) scale(1); }
}
#praise .combo-n {
  font-size: 60px;
  font-style: normal;
  background: linear-gradient(180deg, #ffe89b, #ffb300);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------- tray ---------- */
#tray {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
  width: 100%;
}
.slot {
  width: calc(var(--cell) * 2.9);
  height: calc(var(--cell) * 2.9);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tray-piece {
  position: relative;
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s;
}
.tray-piece.dragging { opacity: 0; }
.tray-piece .block { position: absolute; }

#hint {
  margin-top: 18px;
  font-size: 14px;
  color: rgba(255,255,255,0.75);
  text-align: center;
  padding: 0 24px;
  transition: opacity 0.6s;
}
#hint.hidden { opacity: 0; }

/* ---------- drag layer ---------- */
#drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
#drag-layer .drag-piece { position: absolute; will-change: transform; }
#drag-layer .block { position: absolute; filter: drop-shadow(0 10px 14px rgba(0,0,30,0.4)); }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,16,50,0.72);
  backdrop-filter: blur(3px);
  transition: opacity 0.35s;
}
.screen.hidden { opacity: 0; pointer-events: none; }

#nospace {
  font-size: 40px;
  font-weight: 700;
  font-style: italic;
  text-shadow: 0 3px 0 rgba(0,0,0,0.4);
  animation: praise-pop 1.4s ease forwards;
}

#gameover-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #6b3fd4, #4a2bb0);
  border-radius: 22px;
  padding: 34px 44px;
  box-shadow: 0 16px 40px rgba(0,0,20,0.5), inset 0 2px 0 rgba(255,255,255,0.25);
  animation: panel-in 0.4s cubic-bezier(.2,1.5,.4,1);
}
@keyframes panel-in { from { transform: scale(0.7); opacity: 0; } }
.big-crown { width: 84px; height: 63px; }
#gameover-title { font-size: 24px; font-weight: 700; opacity: 0.9; }
#final-score { font-size: 64px; font-weight: 700; text-shadow: 0 3px 0 rgba(0,0,0,0.3); }
#newbest {
  color: #ffd75e;
  font-weight: 700;
  font-size: 20px;
  animation: will-glow 0.8s ease-in-out infinite;
}
#newbest.hidden, #nospace.hidden, #gameover-panel.hidden { display: none; }

.btn-green {
  margin-top: 10px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  padding: 14px 42px;
  border-radius: 14px;
  background: linear-gradient(180deg, #62d24a, #35a422);
  box-shadow: 0 5px 0 #237c14, 0 8px 16px rgba(0,0,20,0.3), inset 0 2px 0 rgba(255,255,255,0.35);
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
.btn-green:active { transform: translateY(3px); box-shadow: 0 2px 0 #237c14, 0 4px 10px rgba(0,0,20,0.3); }

/* ---------- settings ---------- */
#settings-panel {
  width: min(86vw, 360px);
  background: linear-gradient(180deg, #5a7de4, #3c5ec8);
  border-radius: 22px;
  padding: 20px 22px 26px;
  box-shadow: 0 16px 40px rgba(0,0,20,0.5), inset 0 2px 0 rgba(255,255,255,0.3);
  animation: panel-in 0.35s cubic-bezier(.2,1.5,.4,1);
}
.panel-head {
  display: flex;
  justify-content: center;
  position: relative;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 18px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
#settings-close {
  position: absolute;
  right: -4px; top: 2px;
  background: none;
  border: none;
  color: #cdd9f7;
  font-size: 24px;
  cursor: pointer;
}
.toggles {
  display: flex;
  justify-content: space-around;
  background: rgba(20,40,120,0.35);
  border-radius: 16px;
  padding: 14px 8px;
  margin-bottom: 20px;
}
.toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  padding: 4px 10px;
}
.tgl-icon { font-size: 34px; filter: drop-shadow(0 2px 1px rgba(0,0,0,0.3)); }
.toggle.off .tgl-icon { filter: grayscale(1) opacity(0.55); }
.toggle.off::after {
  content: "";
  position: absolute;
  left: 12%; top: 26px;
  width: 76%; height: 4px;
  background: #e33;
  border-radius: 2px;
  transform: rotate(-32deg);
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}
#restart-btn { width: 100%; }
#restart-btn span { display: inline-block; margin-right: 6px; }

/* small screens */
@media (max-height: 700px) {
  #score { font-size: 48px; }
  #score-wrap { min-height: 56px; }
  #tray { margin-top: 12px; }
  #hint { margin-top: 10px; }
}
