/* ============================================
   WILDSTARZ Puzzle Party — shares design tokens
   with the Match-Up game for a consistent feel.
   ============================================ */

:root {
  --sky-top: #7DD8FF;
  --sky-bot: #EAF9FF;
  --card: #FFFDF7;
  --ink: #2B2450;
  --ink-soft: #6B639A;
  --pink: #FF4FA3;
  --purple: #7B4FFF;
  --green: #2FCB8F;
  --blue: #2EC4F1;
  --orange: #FF9F43;
  --shadow: 0 10px 24px rgba(43, 36, 80, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Quicksand', sans-serif;
  color: var(--ink);
  min-height: 100vh;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* ---------- Sky background ---------- */
.sky { position: fixed; inset: 0; z-index: -1; background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 55%); }
.cloud { position: absolute; background: #fff; opacity: 0.8; border-radius: 100px; }
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 100px; }
.cloud-a { width: 140px; height: 46px; top: 6%; left: 4%; }
.cloud-a::before { width: 70px; height: 70px; top: -34px; left: 14px; }
.cloud-a::after { width: 54px; height: 54px; top: -24px; left: 66px; }
.cloud-b { width: 110px; height: 38px; top: 14%; right: 8%; }
.cloud-b::before { width: 56px; height: 56px; top: -26px; left: 10px; }
.cloud-b::after { width: 44px; height: 44px; top: -18px; left: 52px; }
.cloud-c { width: 90px; height: 32px; top: 4%; left: 42%; opacity: 0.6; }
.cloud-c::before { width: 46px; height: 46px; top: -22px; left: 8px; }
.cloud-c::after { width: 36px; height: 36px; top: -14px; left: 42px; }

/* ---------- App shell ---------- */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar (shared look) ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-star { width: 42px; height: 42px; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.15)); }
.brand h1 { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: clamp(20px, 4vw, 32px); margin: 0; color: #fff; text-shadow: 0 3px 0 rgba(43,36,80,0.25); letter-spacing: 0.5px; }
.brand h1 span { display: block; font-size: 0.42em; font-weight: 600; color: var(--ink); text-shadow: none; letter-spacing: 2px; text-transform: uppercase; opacity: 0.75; }

.stats { display: flex; gap: 10px; }
.stat { background: rgba(255,255,255,0.85); border-radius: 16px; padding: 6px 16px; text-align: center; min-width: 68px; box-shadow: var(--shadow); }
.stat-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); }
.stat-value { display: block; font-family: 'Baloo 2', sans-serif; font-size: 22px; font-weight: 700; color: var(--purple); font-variant-numeric: tabular-nums; }

/* ---------- Difficulty selector (shared look) ---------- */
.difficulty { display: flex; justify-content: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.diff-btn { font-family: 'Quicksand', sans-serif; font-weight: 700; border: none; border-radius: 20px; background: rgba(255,255,255,0.85); color: var(--ink); padding: 10px 20px; display: flex; flex-direction: column; align-items: center; min-width: 84px; cursor: pointer; box-shadow: var(--shadow); transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease; }
.diff-num { font-family: 'Baloo 2', sans-serif; font-size: 22px; font-weight: 800; line-height: 1.1; }
.diff-word { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.7; }
.diff-btn:active { transform: scale(0.94); }
.diff-btn.is-active { background: linear-gradient(135deg, var(--pink), var(--purple)); color: #fff; }
.diff-btn.is-active .diff-word { opacity: 0.9; }

/* ---------- Puzzle area ---------- */
.puzzle-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.puzzle-frame {
  position: relative;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 3 / 2;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #fff;
  border: 4px solid #fff;
}

.ghost-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.16;
  pointer-events: none;
  transition: opacity 0.3s ease;
  user-select: none;
}
.puzzle-frame.is-peeking .ghost-image { opacity: 0.9; }

.grid {
  position: absolute;
  inset: 0;
  display: grid;
  width: 100%;
  height: 100%;
}

.cell {
  position: relative;
  border: 1px dashed rgba(123, 79, 255, 0.25);
}

.cell.is-filled { border: none; }

/* ---------- Tray ---------- */
.tray-wrap {
  width: 100%;
  max-width: 720px;
  background: rgba(255,255,255,0.55);
  border-radius: 20px;
  padding: 14px;
  min-height: 96px;
  box-shadow: var(--shadow);
}
.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* ---------- Puzzle piece ---------- */
.piece {
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(43,36,80,0.25);
  border: 2px solid #fff;
  cursor: grab;
  background-repeat: no-repeat;
  touch-action: none;
  transition: box-shadow 0.15s ease;
}
.piece.is-dragging {
  position: fixed;
  z-index: 200;
  cursor: grabbing;
  box-shadow: 0 14px 28px rgba(43,36,80,0.4);
  transition: none;
}
.piece.is-placed {
  position: absolute;
  inset: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
  cursor: default;
  animation: placePop 0.4s cubic-bezier(.4,1.8,.6,1);
}
@keyframes placePop {
  0% { transform: scale(1.3); filter: brightness(1.3); }
  60% { transform: scale(0.96); }
  100% { transform: scale(1); filter: brightness(1); }
}
.piece.snap-back {
  animation: snapBack 0.3s ease;
}
@keyframes snapBack {
  0% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* ---------- Buttons row ---------- */
.newgame-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.newgame-btn {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: 30px;
  padding: 13px 26px;
  background: #fff;
  color: var(--purple);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.newgame-btn svg { width: 18px; height: 18px; fill: var(--purple); }
.newgame-btn:active { transform: scale(0.95); }

/* ---------- Win overlay (shared look) ---------- */
.win-overlay {
  position: fixed; inset: 0; background: rgba(43, 36, 80, 0.55);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease; z-index: 50; padding: 20px;
}
.win-overlay.is-open { opacity: 1; pointer-events: auto; }
.win-card {
  background: var(--card); border-radius: 28px; padding: 32px 28px 28px; max-width: 440px; width: 100%;
  text-align: center; position: relative; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  transform: scale(0.85) translateY(10px); transition: transform 0.35s cubic-bezier(.4,1.8,.6,1);
}
.win-overlay.is-open .win-card { transform: scale(1) translateY(0); }
.win-card h2 { font-family: 'Baloo 2', sans-serif; font-size: 26px; color: var(--purple); margin: 4px 0 4px; }
.win-card p { margin: 0 0 16px; color: var(--ink-soft); font-weight: 600; }
.win-scene { width: 100%; border-radius: 16px; margin-bottom: 20px; box-shadow: var(--shadow); }
.playagain-btn {
  font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 16px; border: none; border-radius: 26px;
  padding: 13px 30px; background: linear-gradient(135deg, var(--pink), var(--purple)); color: #fff; cursor: pointer;
}
.playagain-btn:active { transform: scale(0.96); }
.win-burst { position: absolute; inset: 0; pointer-events: none; }
.confetti { position: absolute; top: -10px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(340px) rotate(360deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .piece, .win-card, .win-overlay, .ghost-image { transition: none !important; animation: none !important; }
}
