:root {
  --tg-bg: #fff5fb;
  --tg-text: #3a2540;
  --tg-accent: #ff5aa8;

  --bg1: #ffe3f2;
  --bg2: #e3e0ff;
  --bg3: #fff0d6;
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-border: rgba(255, 255, 255, 0.9);
  --text-main: #3a2540;
  --text-soft: #8b7793;
  --accent: #ff5aa8;
  --accent-2: #a86bff;
  --shadow-soft: 0 10px 30px rgba(168, 107, 255, 0.18);
  --radius-lg: 28px;
  --radius-md: 18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: "Quicksand", sans-serif;
  color: var(--text-main);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3));
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body.in-telegram {
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3));
}

h1, h2 { font-family: "Baloo 2", "Quicksand", sans-serif; margin: 0; }

#app {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

/* ---------- Фоновые декоративные пузыри ---------- */
.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  max-width: 480px;
  margin: 0 auto;
}
.bubble {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.5;
  animation: float 12s ease-in-out infinite;
}
.b1 { width: 90px; height: 90px; left: 8%; top: 12%; background: radial-gradient(circle at 30% 30%, #ffd1ec, transparent 70%); animation-duration: 14s; }
.b2 { width: 60px; height: 60px; right: 10%; top: 22%; background: radial-gradient(circle at 30% 30%, #d9c7ff, transparent 70%); animation-duration: 11s; animation-delay: 1s; }
.b3 { width: 120px; height: 120px; left: -20px; bottom: 18%; background: radial-gradient(circle at 30% 30%, #ffe6b0, transparent 70%); animation-duration: 16s; }
.b4 { width: 45px; height: 45px; right: 6%; bottom: 30%; background: radial-gradient(circle at 30% 30%, #b9f3e2, transparent 70%); animation-duration: 9s; animation-delay: .5s; }
.b5 { width: 70px; height: 70px; right: 30%; top: 5%; background: radial-gradient(circle at 30% 30%, #ffc2d9, transparent 70%); animation-duration: 13s; animation-delay: 2s; }

@keyframes float {
  0%, 100% { transform: translateY(0) translateX(0); }
  50% { transform: translateY(-24px) translateX(10px); }
}

/* ---------- Экраны ---------- */
.screen { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- Приветствие ---------- */
#screen-welcome { align-items: center; justify-content: center; padding: 24px 18px; }
.welcome-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  width: 100%;
  max-width: 380px;
}
.welcome-emoji { font-size: 34px; margin-bottom: 6px; letter-spacing: 4px; }

.cover-hero {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 260px;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(168, 107, 255, 0.25);
}
.cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ffe3f2, #e3e0ff);
}

.welcome-card h1 {
  font-size: 30px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--text-soft); font-size: 14.5px; margin: 10px 0 20px; line-height: 1.4; }

.nick-label { display: block; text-align: left; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; font-weight: 600; }
.nick-input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 2px solid #ffd6ec;
  background: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 14px;
  outline: none;
  transition: border-color .15s;
}
.nick-input:focus { border-color: var(--accent); }

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 10px;
  transition: transform .08s ease, box-shadow .15s ease, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px rgba(255, 90, 168, 0.4);
}
.btn-ghost {
  background: #fff;
  color: var(--accent-2);
  border: 2px solid #ecdcff;
}

.howto { margin-top: 18px; text-align: left; background: #fff8fd; border-radius: 16px; padding: 14px 16px; }
.howto-title { font-weight: 700; color: var(--accent-2); font-size: 13px; margin-bottom: 8px; }
.howto-row { font-size: 13.5px; color: var(--text-soft); margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.howto-icon { font-size: 16px; }
.howto-icon-img {
  width: 30px;
  height: 30px;
  min-width: 30px;
  object-fit: contain;
  border-radius: 9px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

/* ---------- Игровой экран ---------- */
#screen-game { padding: 12px 12px 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 10px;
}
.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.stat {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 6px 12px;
  backdrop-filter: blur(10px);
  text-align: center;
}
.stat-label { font-size: 10.5px; color: var(--text-soft); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stat-value { font-size: 18px; font-weight: 800; color: var(--accent-2); font-family: "Baloo 2", sans-serif; }

.coin-pill {
  background: linear-gradient(135deg, #fff3c2, #ffd966);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 14px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
  color: #7a5300;
  white-space: nowrap;
  box-shadow: 0 3px 8px rgba(200,140,0,0.25);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: inherit;
}
.coin-pill:active { transform: scale(0.96); }
.coin-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(122, 83, 0, 0.18);
  font-size: 11px;
  line-height: 1;
}

.next-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.next-label { font-size: 12px; color: var(--text-soft); font-weight: 700; }
.next-item {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
}
.next-item .tile-svg { width: 74%; height: 74%; }
.next-item .tile-img { width: 78%; height: 78%; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: var(--cols) / var(--rows);
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  overflow: hidden;
  backdrop-filter: blur(6px);
  touch-action: none;
}

.cell-slot {
  position: absolute;
  width: calc(100% / 6);
  height: calc(100% / 8);
  box-shadow: inset 0 0 0 1px rgba(168,107,255,0.07);
  border-radius: 14%;
}

/* позиционируем cell-slot через nth-child, т.к. COLS/ROWS фиксированы в разметке JS */
.board .cell-slot:nth-child(n) { }

.tile {
  position: absolute;
  padding: 3px;
  will-change: left, top, transform;
  cursor: grab;
  touch-action: none;
}
.tile.dragging { cursor: grabbing; filter: drop-shadow(0 10px 14px rgba(0,0,0,0.25)); }

.tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08), inset 0 0 0 1px rgba(255,255,255,0.6), 0 0 14px var(--glow, transparent);
}
.tile-art { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.tile-img {
  width: 80%;
  height: 80%;
  object-fit: contain;
  border-radius: 18%;
  background: #fffdfb;
  box-shadow: 0 3px 8px rgba(0,0,0,0.16);
  pointer-events: none;
}
.tile-fallback {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}
.tile-svg { width: 68%; height: 68%; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15)); }
.tile-lv {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 9px;
  font-weight: 800;
  color: rgba(0,0,0,0.35);
}

/* Категории: тонкая цветная рамка + маленький бейдж категории */
.tile-inner.cat-fashion,
.tile-inner.cat-sweets,
.tile-inner.cat-beauty {
  box-shadow: 0 4px 10px rgba(0,0,0,0.08), inset 0 0 0 1px rgba(255,255,255,0.6),
    0 0 14px var(--glow, transparent), inset 0 0 0 2px var(--cat-ring, transparent);
}
.tile-cat-badge {
  position: absolute;
  bottom: 2px;
  left: 4px;
  font-size: 10px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25));
}

/* Блокер "Корзина с бельём" */
.tile-blocker {
  background: linear-gradient(145deg, #eceef2, #c7cbd4) !important;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12), inset 0 0 0 1px rgba(255,255,255,0.5) !important;
}
.blocker-art { flex-direction: column; gap: 2px; }
.blocker-img {
  width: 74%;
  height: 74%;
  object-fit: contain;
  border-radius: 16%;
  pointer-events: none;
}
.blocker-emoji { font-size: clamp(18px, 6vw, 30px); line-height: 1; }
.blocker-dots { font-size: 8px; letter-spacing: 2px; color: #6b7280; }
.blocker-hit .blocker-img,
.blocker-hit .blocker-emoji { animation: blocker-shake .3s ease; }
@keyframes blocker-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px) rotate(-6deg); }
  75% { transform: translateX(4px) rotate(6deg); }
}

/* Режим прицеливания бустером (бомба/порошок) */
.board.targeting { cursor: crosshair; }
.board.targeting .tile { cursor: crosshair; }
.board.targeting::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 90, 168, 0.06);
  pointer-events: none;
  animation: targeting-pulse 1s ease-in-out infinite;
}
@keyframes targeting-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Всплывающая подпись комбо */
.combo-toast {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 13px;
  color: #ff5aa8;
  text-shadow: 0 2px 4px rgba(255,255,255,0.8);
  pointer-events: none;
  animation: combo-float .9s ease-out forwards;
  z-index: 40;
}
@keyframes combo-float {
  0% { opacity: 0; transform: translate(-50%, -50%) translateY(0) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -50%) translateY(-6px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50%) translateY(-40px) scale(1); }
}

.tile-sparkle::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 20%;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.9), transparent 70%);
  background-size: 250% 250%;
  animation: sparkle-sweep 2.2s linear infinite;
  pointer-events: none;
}
@keyframes sparkle-sweep {
  0% { background-position: 200% 0; }
  100% { background-position: -50% 0; }
}

.merge-target .tile-inner {
  animation: pulse-target .5s ease-in-out infinite;
}
@keyframes pulse-target {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.particle {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  pointer-events: none;
  animation: particle-fly .55s ease-out forwards;
}
@keyframes particle-fly {
  0% { opacity: 1; transform: translate(-50%, -50%) translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) translate(var(--dx), var(--dy)) scale(0.3); }
}

.bottombar { padding: 14px 4px 18px; }
.btn-spawn { position: relative; display: flex; align-items: center; justify-content: center; gap: 6px; }

.booster-tray {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.booster-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 2px solid #ecdcff;
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
  transition: transform .08s ease, border-color .15s, opacity .15s;
}
.booster-btn:active { transform: scale(0.95); }
.booster-icon { font-size: 30px; line-height: 1; }
.booster-icon-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 10px;
  pointer-events: none;
}
.booster-cost { font-size: 11px; font-weight: 800; color: var(--accent-2); }
.booster-btn.armed { border-color: var(--accent); background: #fff0f7; }
.booster-btn.disabled { opacity: 0.45; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(58, 37, 64, 0.92);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
  max-width: 85%;
  text-align: center;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Модалки ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(58, 37, 64, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  position: relative;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 26px 22px 22px;
  width: 100%;
  max-width: 380px;
  max-height: 82vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 20px 60px rgba(58,37,64,0.35);
}
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: #f6eefb;
  color: var(--text-soft);
  font-size: 14px;
  cursor: pointer;
}
.modal h2 { font-size: 20px; margin-bottom: 6px; color: var(--text-main); }

/* Рейтинг */
.lb-status { font-size: 13px; color: var(--text-soft); margin: 6px 0 10px; }
.lb-list { list-style: none; margin: 0; padding: 0; text-align: left; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
  background: #fdf3fb;
}
.lb-rank { width: 26px; text-align: center; font-weight: 800; color: var(--accent-2); }
.lb-name { flex: 1; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--accent); }

/* Магазин монет */
.shop-sub { color: var(--text-soft); font-size: 13px; margin: 6px 0 16px; line-height: 1.4; }
.shop-list { display: flex; flex-direction: column; gap: 10px; }
.shop-pack {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border: 2px solid #ffe9c2;
  border-radius: 16px;
  background: #fffaf0;
  cursor: pointer;
  font-family: inherit;
  transition: transform .08s ease;
}
.shop-pack:active { transform: scale(0.97); }
.shop-pack-coins { font-size: 17px; font-weight: 800; color: #7a5300; }
.shop-pack-price { font-size: 15px; font-weight: 700; color: var(--accent-2); }
.shop-pack-popular { border-color: var(--accent); background: #fff0f7; }
.shop-pack-badge {
  position: absolute;
  top: -9px; left: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 8px;
}

/* Level up */
.modal-levelup-card { padding-top: 34px; overflow: hidden; }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.levelup-emoji { width: 96px; height: 96px; margin: 0 auto 6px; animation: pop-in .4s cubic-bezier(.34,1.56,.64,1); }
.levelup-emoji .tile-svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.18)); }
.levelup-emoji .tile-img { width: 88%; height: 88%; box-shadow: 0 6px 16px rgba(0,0,0,0.22); }
.levelup-name { font-size: 16px; font-weight: 700; color: var(--accent-2); margin: 4px 0 18px; }
@keyframes pop-in {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Game over */
.go-sub { color: var(--text-soft); margin: 6px 0 2px; font-size: 14px; }
.go-score { font-size: 40px; font-weight: 800; font-family: "Baloo 2", sans-serif; color: var(--accent); margin-bottom: 6px; }
.go-best-item { font-size: 14px; color: var(--text-soft); margin-bottom: 18px; }

.menu-nick { margin-top: 12px; text-align: left; }
.menu-nick label { font-size: 12px; color: var(--text-soft); font-weight: 700; }

@media (prefers-color-scheme: dark) {
  :root {
    --card-bg: rgba(40, 28, 46, 0.65);
    --card-border: rgba(255,255,255,0.12);
    --text-main: #f5e9f7;
    --text-soft: #c3aecb;
  }
  body { background: linear-gradient(160deg, #2a1a33, #1d1730 55%, #241a2e); }
  .modal-card { background: #241a2e; color: var(--text-main); }
  .nick-input, .howto, .lb-row, .icon-btn, .booster-btn { background: rgba(255,255,255,0.06); color: var(--text-main); }
  .nick-input, .booster-btn { border-color: rgba(255,255,255,0.15); }
  .btn-ghost { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.15); }
  .booster-btn.armed { border-color: var(--accent); background: rgba(255,90,168,0.12); }
  .shop-pack { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.15); }
  .shop-pack-popular { background: rgba(255,90,168,0.12); border-color: var(--accent); }
  .shop-pack-coins { color: #ffd966; }
}
