:root {
  --bg: #0a0b12;
  --bg-2: #12131d;
  --surface: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eef0f5;
  --text-dim: #9aa0ae;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #4ade80;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}
body {
  font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(70vmax 55vmax at 50% -10%, rgba(124, 92, 255, 0.28), transparent 70%),
    radial-gradient(50vmax 40vmax at 100% 20%, rgba(34, 211, 238, 0.14), transparent 70%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
body.in-game { overflow: hidden; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 14px calc(env(safe-area-inset-bottom) + 20px);
  min-height: 100%;
}

button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; }
.brand-logo { color: var(--accent); filter: drop-shadow(0 0 8px rgba(124, 92, 255, 0.7)); }

.coins {
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 1.2rem;
  font-weight: 700;
  display: grid; place-items: center;
  transition: transform 0.12s, border-color 0.2s;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- level select ---------- */
.ls-head, .ls-head-right { display: flex; align-items: center; gap: 10px; }
.ls-head { justify-content: space-between; margin-bottom: 20px; }

.ls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 12px;
}
.ls-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: 18px;
  background: linear-gradient(160deg, var(--bg-2), #0c0d15);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.12s, border-color 0.2s;
  overflow: hidden;
}
.ls-card:active { transform: scale(0.94); }
.ls-card.hard { border-color: color-mix(in srgb, var(--accent, #7B1FA2) 55%, transparent); }
.ls-card.locked { opacity: 0.45; }
.ls-num { font-size: 1.5rem; font-weight: 700; }
.ls-badge {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--accent, #7B1FA2);
  border-radius: 999px;
  padding: 2px 7px;
}
.ls-stars { font-size: 0.8rem; color: #ffd166; letter-spacing: 1px; }
.ls-foot { text-align: center; color: var(--text-dim); font-size: 0.78rem; margin-top: 22px; }

/* ---------- dialogs ---------- */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 5, 9, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 100;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(160deg, #171822, #101017);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px;
  text-align: center;
  animation: pop 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.dialog h2 { font-size: 1.3rem; margin-bottom: 10px; }
.dialog h3 { font-size: 0.95rem; margin: 14px 0 8px; color: var(--text-dim); }
.dialog p { color: var(--text-dim); font-size: 0.92rem; margin: 4px 0; }
.dialog-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.dialog-actions button { flex: 1; min-width: 110px; padding: 12px; border-radius: 12px; font-weight: 600; }
.btn-primary { background: linear-gradient(120deg, var(--accent), #9d7bff); color: #fff; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); }
.btn-primary:disabled { opacity: 0.5; }

.bd-obj { text-align: left; margin: 12px 0; font-size: 0.9rem; color: var(--text-dim); display: grid; gap: 3px; }
.bd-meta { font-size: 0.82rem; color: var(--text-dim); }
.bd-boosters { text-align: left; margin-top: 8px; }
.bd-booster {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 6px;
  font-size: 0.85rem;
}
.bd-booster small { color: var(--text-dim); }
.bd-booster input { width: 18px; height: 18px; accent-color: var(--accent); }
.bd-cost { margin-left: auto; white-space: nowrap; color: #ffd166; font-weight: 600; }
.bd-total { display: block; margin-top: 8px; font-size: 0.85rem; color: var(--text-dim); }

.tut .tut-emoji { font-size: 2.6rem; }
.tut-steps { text-align: left; margin: 14px 0 20px; padding-left: 22px; display: grid; gap: 10px; font-size: 0.9rem; }
.tut-steps li { color: var(--text); }
.tut .btn-primary { width: 100%; padding: 13px; border-radius: 12px; font-weight: 600; }

.result-stars { font-size: 2.2rem; color: #ffd166; letter-spacing: 4px; margin-bottom: 6px; }
.result-emoji { font-size: 2.6rem; }
.result.win h2 { color: var(--ok); }

/* ---------- game screen ---------- */
.game-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.stat-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.stat-val { font-size: 1.15rem; font-weight: 700; }
.game-top .stat { flex: 1; }

.board-wrap { display: flex; justify-content: center; }
.board {
  position: relative;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  box-shadow: inset 0 0 0 1px var(--border);
  overflow: hidden;
  touch-action: none;
}
.board.shake { animation: shake 0.32s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}
.board.page-in { animation: pagein 0.5s ease; }
@keyframes pagein { from { opacity: 0.2; transform: translateX(18px); } }

.tile {
  position: absolute;
  top: 0; left: 0;
  padding: 3px;
  transition: transform 0.22s cubic-bezier(0.2, 0.75, 0.3, 1), opacity 0.2s ease;
  will-change: transform;
}
.tile::before {
  content: "";
  display: block;
  width: 100%; height: 100%;
  border-radius: 22%;
  background: var(--fill, #2a2d3a);
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.32), inset 0 2px 3px rgba(255, 255, 255, 0.22);
}
.tile::after {
  content: "";
  position: absolute;
  inset: 22%;
  background: rgba(255, 255, 255, 0.92);
}
.tile.clearing { transform: scale(0) !important; opacity: 0; }
.tile.selected::before { box-shadow: inset 0 0 0 3px #fff, inset 0 -3px 5px rgba(0, 0, 0, 0.3); }

.shape-ball { --fill: linear-gradient(160deg, #ef5350, #c62828); }
.shape-ball::after { border-radius: 50%; }
.shape-triangle { --fill: linear-gradient(160deg, #66bb6a, #2e7d32); }
.shape-triangle::after { clip-path: polygon(50% 6%, 96% 92%, 4% 92%); }
.shape-square { --fill: linear-gradient(160deg, #f06292, #c2185b); }
.shape-square::after { border-radius: 12%; inset: 24%; }
.shape-cross { --fill: linear-gradient(160deg, #42a5f5, #1565c0); }
.shape-cross::after {
  clip-path: polygon(20% 0, 50% 30%, 80% 0, 100% 20%, 70% 50%, 100% 80%, 80% 100%, 50% 70%, 20% 100%, 0 80%, 30% 50%, 0 20%);
}

/* specials */
.sp-striped-h::after { clip-path: none; border-radius: 2px; inset: 30% 12%; background: repeating-linear-gradient(90deg, #fff 0 3px, transparent 3px 7px); }
.sp-striped-v::after { clip-path: none; border-radius: 2px; inset: 12% 30%; background: repeating-linear-gradient(0deg, #fff 0 3px, transparent 3px 7px); }
.sp-bomb::before { --fill: radial-gradient(circle at 35% 30%, #6a6a6a, #0c0c0c); border-radius: 50%; }
.sp-bomb::after { inset: 30%; border-radius: 50%; background: rgba(255, 255, 255, 0.28); }
.sp-color::before { --fill: radial-gradient(circle at 35% 30%, #fff, #e6e0ff 45%, #b39ddb 75%, #7e57c2); border-radius: 50%; }
.sp-color::after { display: none; }

/* box */
.tile.box::before { --fill: linear-gradient(160deg, #a1662f, #6d3f16); }
.tile.box::after {
  inset: 14%; clip-path: none; background: transparent;
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08) inset;
}
.tile.box { --grid: 1; }
.tile.box .lid, .tile.box::after { border-radius: 4px; }

/* fire */
.tile.fire::before { --fill: linear-gradient(0deg, #ff9800, #ff5722); border-radius: 30% 30% 45% 45%; }
.tile.fire::after {
  inset: 16% 24% 8%; clip-path: polygon(50% 0, 80% 45%, 68% 100%, 32% 100%, 20% 45%);
  background: linear-gradient(0deg, #ffd54f, #ffab40);
}
.tile.fire-1::after { inset: 40% 30% 8%; }
.tile.fire-2::after { inset: 30% 28% 8%; }
.tile.fire-3::after { inset: 20% 25% 8%; }
.tile.fire-4::after { inset: 10% 22% 6%; }

/* barrel */
.tile.barrel::before { --fill: linear-gradient(160deg, #37474f, #1c262b); }
.tile.barrel::after {
  inset: 14% 26%; clip-path: none; border-radius: 3px;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.15) 0 3px, transparent 3px 9px);
}

/* ice overlay */
.tile.ice::before { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.5), inset 0 -3px 5px rgba(0, 0, 0, 0.3); }
.tile.ice-1::before { background-image: linear-gradient(160deg, rgba(190, 225, 255, 0.55), rgba(120, 190, 255, 0.4)); }
.tile.ice-2::before { background-image: linear-gradient(160deg, rgba(150, 130, 255, 0.6), rgba(90, 150, 255, 0.5)); }
.tile.ice-3::before { background-image: linear-gradient(160deg, rgba(160, 110, 255, 0.6), rgba(80, 220, 170, 0.5)); }
.tile.ice-4::before { background-image: linear-gradient(120deg, #ff6b9d80, #ffd16680, #4ade8080, #22d3ee80, #7c5cff80); }

/* jelly */
.tile.jelly::before { --fill: rgba(120, 220, 200, 0.28); backdrop-filter: blur(1px); }
.tile.jelly::after {
  clip-path: none; inset: 34%; background: transparent;
  color: rgba(255, 255, 255, 0.9); font-size: 0;
}
.tile.jelly-1::before { --fill: rgba(120, 220, 200, 0.24); }
.tile.jelly-2::before { --fill: rgba(120, 200, 255, 0.3); }
.tile.jelly-3::before { --fill: rgba(150, 150, 255, 0.34); }
.tile.jelly-4::before { --fill: rgba(190, 130, 255, 0.4); }
.tile.jelly-5::before { --fill: rgba(150, 90, 220, 0.55); }
.tile.jelly::after {
  content: attr(data-jelly);
  display: grid; place-items: center;
  inset: 0; font-size: 0.7em; font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.tile.has-grape::before { box-shadow: inset 0 0 0 2px rgba(190, 120, 255, 0.8), inset 0 -3px 5px rgba(0,0,0,.3); }
.tile.has-grape.jelly::after { content: "🍇"; font-size: 0.9em; }

/* objectives */
.obj-list {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}
.obj {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.88rem;
}
.obj-check {
  width: 20px; height: 20px; flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--text-dim);
  display: grid; place-items: center;
  font-size: 0.75rem; color: var(--ok);
}
.obj.done { border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.obj.done .obj-check { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.obj-prog { margin-left: auto; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* install hint */
.install-hint {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  display: flex; align-items: center; gap: 10px;
  background: rgba(20, 21, 28, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.82rem;
  z-index: 90;
}
.install-hint .icon-btn { width: 30px; height: 30px; font-size: 0.9rem; margin-left: auto; flex-shrink: 0; }

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .board.shake, .board.page-in { animation: none; }
}
