/* ============================================
   WILDSTARZ Match-Up — design tokens
   Colors:
     --sky-top:   #7DD8FF
     --sky-bot:   #EAF9FF
     --sun:       #FFE27A -> #FF6B35 (card back gradient)
     --card:      #FFFDF7
     --ink:       #2B2450
     --pink:      #FF4FA3
     --purple:    #7B4FFF
     --green:     #2FCB8F
     --blue:      #2EC4F1
   Type: 'Baloo 2' (display), 'Quicksand' (ui)
   ============================================ */

: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: manipulation;
}

/* ---------- 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;
  filter: blur(0.5px);
}
.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 ---------- */
.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(22px, 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.45em;
  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 ---------- */
.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; }

/* ---------- Board ---------- */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board {
  display: grid;
  gap: clamp(8px, 1.6vw, 16px);
  width: 100%;
}
.board[data-count="6"]  { grid-template-columns: repeat(3, 1fr); max-width: 560px; }
.board[data-count="12"] { grid-template-columns: repeat(4, 1fr); max-width: 720px; }
.board[data-count="24"] { grid-template-columns: repeat(6, 1fr); max-width: 980px; }

/* ---------- Card ---------- */
.card {
  aspect-ratio: 3 / 4;
  perspective: 900px;
  cursor: pointer;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.4,1.8,.6,1);
}
.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card-back {
  background: linear-gradient(160deg, #FFE27A, #FF9F43 55%, #FF6B35);
  padding: 12%;
}
.card-back svg { width: 100%; height: 100%; }
.card-front {
  background: var(--card);
  transform: rotateY(180deg);
  flex-direction: column;
  padding: 8% 6% 4%;
  border: 3px solid #fff;
}
.card-front img {
  width: 100%;
  height: 78%;
  object-fit: contain;
}
.card-name {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: clamp(10px, 1.6vw, 15px);
  color: var(--purple);
  margin-top: 2%;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.card.is-matched .card-name { opacity: 1; transform: translateY(0); }
.card.is-matched .card-front {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(47,203,143,0.25), var(--shadow);
}
.card.is-matched { cursor: default; animation: settle 0.5s ease 0.35s; }
@keyframes settle {
  0% { transform: scale(1); }
  40% { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.card.is-wrong .card-front {
  animation: shake 0.4s ease;
  border-color: var(--pink);
}
@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-4%); }
  75% { transform: rotateY(180deg) translateX(4%); }
}

.card:not(.is-flipped):not(.is-matched):active .card-back {
  filter: brightness(0.95);
}

/* ---------- New Game button ---------- */
.newgame-row {
  display: flex;
  justify-content: center;
  margin-top: 24px;
}
.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 ---------- */
.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: 420px;
  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-cast {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.win-cast img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #F4F1FF;
  border-radius: 12px;
  padding: 4px;
}
.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; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .board[data-count="24"] { grid-template-columns: repeat(4, 1fr); }
  .stats { gap: 6px; }
  .stat { padding: 5px 12px; min-width: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner, .card.is-matched, .card-name, .win-card, .win-overlay { transition: none !important; animation: none !important; }
}
