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

:root {
  --bg: #3b1145; --panel: #4a1a55; --panel2: #5c2569;
  --ink: #fdeaff; --gold: #ffd43b; --muted: rgba(253,234,255,.62);
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: radial-gradient(circle at 50% 12%, #5e2170, #3b1145 72%);
  font-family: -apple-system, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}

.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 10; }
#game.screen { justify-content: flex-start; }
.panel { text-align: center; padding: 26px; width: min(400px, 94vw); animation: pin .3s ease; }
@keyframes pin { from { transform: translateY(16px) scale(.97); opacity: 0; } }

.logoK { font-size: 54px; }
h1 { font-size: 42px; font-weight: 900; letter-spacing: 1px; line-height: 1; }
h1 span {
  display: block; font-size: 24px; letter-spacing: 6px;
  background: linear-gradient(135deg, #ffd6f0, #ff8ad4, #ffd43b);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
h2 { font-size: 30px; font-weight: 900; letter-spacing: 2px; margin-bottom: 8px; }
.tag { color: var(--muted); font-weight: 600; margin: 10px 0 20px; }

button.big {
  display: block; width: 100%; margin: 10px 0; padding: 15px 0;
  font-size: 18px; font-weight: 900; letter-spacing: 1px;
  color: #58123f; background: linear-gradient(135deg, #ffd6f0, #ff8ad4);
  border: none; border-radius: 16px; cursor: pointer;
  box-shadow: 0 5px 0 #c2508f, 0 10px 24px rgba(0,0,0,.4);
}
button.big small { display: block; font-size: 11px; font-weight: 700; opacity: .7; margin-top: 2px; }
button.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #c2508f; }
button.big.share { color: #4a2c00; background: linear-gradient(135deg, #ffe07a, #ffd43b); box-shadow: 0 5px 0 #c77e0a, 0 10px 24px rgba(0,0,0,.4); }
button.big.share:active { box-shadow: 0 2px 0 #c77e0a; }
.ghost { display: inline-block; background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 700; margin-top: 8px; text-decoration: none; padding: 14px 12px; }
.best { color: var(--gold); font-weight: 800; margin-top: 16px; min-height: 20px; }
.lvlBadge {
  display: inline-block; margin-bottom: 10px; padding: 5px 18px;
  font-size: 14px; font-weight: 900; letter-spacing: 2px; color: var(--gold);
  background: rgba(255,212,59,.14); border: 1px solid rgba(255,212,59,.4); border-radius: 20px;
}
#level { color: var(--gold); }
.hint { color: var(--muted); font-size: 13px; font-weight: 600; }
#lvlMap { display: flex; gap: 8px; justify-content: center; margin: 2px 0 6px; }
.lvlChip {
  width: 52px; padding: 6px 0 5px; border-radius: 12px; text-align: center;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12);
}
.lvlChip b { display: block; font-size: 15px; font-weight: 900; }
.lvlChip span { display: block; font-size: 13px; min-height: 17px; }
.lvlChip.done { opacity: .45; }
.lvlChip.done b { color: #8ce99a; }
.lvlChip.cur { background: rgba(255,212,59,.16); border-color: rgba(255,212,59,.55); box-shadow: 0 0 14px rgba(255,212,59,.2); }
.lvlChip.cur b { color: var(--gold); }
.nextHint { color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 6px; }

/* ================= game ================= */
#topBar {
  width: 100%; max-width: 520px;
  display: flex; align-items: center; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 62px 8px 16px;
  position: relative;
}
.stat { text-align: center; }
.stat span { display: block; font-size: 10px; font-weight: 800; letter-spacing: 1px; color: var(--muted); }
.stat b { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat b.bump { animation: bump .2s ease; }
@keyframes bump { 40% { transform: scale(1.25); color: var(--gold); } }
.progWrap { flex: 1; height: 12px; background: var(--panel); border-radius: 8px; position: relative; }
#progFill { height: 100%; width: 0%; border-radius: 8px; background: linear-gradient(90deg, #ff8ad4, var(--gold)); transition: width .3s; }
#progTarget { position: absolute; right: 8px; top: -18px; font-size: 11px; font-weight: 800; color: var(--muted); }
.quit { position: absolute; right: 10px; top: max(8px, env(safe-area-inset-top)); width: 44px; height: 44px; border-radius: 12px; border: none; background: rgba(255,255,255,.14); color: var(--ink); font-size: 19px; font-weight: 800; cursor: pointer; }
.quit:active { transform: scale(.92); }

#boardWrap { width: min(96vw, 520px); aspect-ratio: 1; margin: auto; }
#board {
  position: relative; width: 100%; height: 100%;
  background: rgba(0,0,0,.22);
  border-radius: 16px; padding: 2%;
  box-shadow: inset 0 2px 12px rgba(0,0,0,.4);
}
.cell {
  position: absolute;
  width: 12.5%; height: 12.5%;
  display: flex; align-items: center; justify-content: center;
  transition: left .18s ease, top .22s cubic-bezier(.3,.8,.4,1);
  will-change: left, top;
}
.candy {
  width: 82%; height: 82%;
  border-radius: 30%;
  display: flex; align-items: center; justify-content: center;
  font-size: 4.6vmin;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.28), inset 0 3px 6px rgba(255,255,255,.4), 0 2px 4px rgba(0,0,0,.3);
  transition: transform .12s;
}
@media (min-width: 520px) { .candy { font-size: 26px; } }
.cell.sel .candy { transform: scale(1.18); box-shadow: 0 0 0 3px #fff, 0 0 16px rgba(255,255,255,.7); }
.cell.clearing .candy { animation: pop .22s ease forwards; }
@keyframes pop { 60% { transform: scale(1.3); } 100% { transform: scale(0); opacity: 0; } }
.cell.spawn .candy { animation: drop .2s ease; }
@keyframes drop { from { transform: scale(.4); } }

.c0 { background: linear-gradient(145deg, #ff7a90, #e03b5a); }   /* red */
.c1 { background: linear-gradient(145deg, #ffd166, #f5a623); }   /* orange */
.c2 { background: linear-gradient(145deg, #fff27a, #f5d000); }   /* yellow */
.c3 { background: linear-gradient(145deg, #8ce99a, #37b24d); }   /* green */
.c4 { background: linear-gradient(145deg, #74c0fc, #1c7ed6); }   /* blue */
.c5 { background: linear-gradient(145deg, #d0bfff, #7048e8); }   /* purple */
.candy.stripedH::after, .candy.stripedV::after { content: ''; position: absolute; background: rgba(255,255,255,.6); }
.candy.stripedH::after { left: 6%; right: 6%; height: 16%; border-radius: 3px; }
.candy.stripedV::after { top: 6%; bottom: 6%; width: 16%; border-radius: 3px; }
.candy.wrapped { box-shadow: inset 0 0 0 3px rgba(255,255,255,.7), 0 0 12px rgba(255,255,255,.5); }
.candy.bomb { background: radial-gradient(circle at 35% 30%, #fff, #333 70%) !important; }
.candy.bomb::after { content: '✦'; color: #fff; font-size: 4vmin; }

#bigMsg {
  position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%);
  font-size: 44px; font-weight: 900; font-style: italic;
  text-shadow: 0 6px 20px rgba(0,0,0,.6); pointer-events: none; opacity: 0; z-index: 8;
}
#bigMsg.show { animation: bigPop 1s ease; }
@keyframes bigPop { 0% { transform: translate(-50%,-50%) scale(.3); opacity: 0; } 25% { transform: translate(-50%,-50%) scale(1.15); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(-50%,-50%) scale(1); opacity: 0; } }

.coinWin {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,212,59,.15); border: 1px solid rgba(255,212,59,.4);
  color: var(--gold); font-weight: 900; font-size: 18px;
  padding: 6px 18px; border-radius: 20px; margin-bottom: 12px;
}

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

#board.shake { animation: bshake .28s cubic-bezier(.36,.07,.19,.97); }
@keyframes bshake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
