:root {
  --pink: #ff5d8f;
  --purple: #9b7bff;
  --blue: #3fa9f5;
  --green: #5fd35f;
  --yellow: #ffd23d;
  --orange: #ff9f43;
  --ink: #3a2c5a;
  --panel: #fffdf7;
}

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

html, body {
  margin: 0;
  height: 100%;
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #fce4ec 0%, #e8eaf6 50%, #e0f2f1 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body { display: flex; flex-direction: column; }

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

.topbar {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(120,80,160,0.15);
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }
.topbar > * { flex: 0 0 auto; }
.topbar-spacer { flex: 1 1 auto; min-width: clamp(80px,20vw,280px); }

.site-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 900;
  text-decoration: none;
}
.site-logo-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: var(--pink);
  color: #fff;
  box-shadow: 3px 3px 0 rgba(58,44,90,0.28);
  font-size: 0.72rem;
  letter-spacing: 0;
}

.logo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.25rem;
  font-weight: 800;
  max-width: min(38vw,340px);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
  pointer-events: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #fff;
  border-radius: 999px;
  padding: 4px 11px;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 2px 6px rgba(120,80,160,0.18);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.15rem;
  background: #fff;
  box-shadow: 0 3px 8px rgba(120,80,160,0.22);
  display: grid;
  place-items: center;
  transition: transform 0.1s;
}
.icon-btn:active { transform: scale(0.9); }

.btn {
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.12); }
.btn.green { background: var(--green); }
.btn.blue { background: var(--blue); }
.btn.orange { background: var(--orange); }
.btn.pink { background: var(--pink); }

.play-area {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
  gap: 10px;
}

.setup-box {
  text-align: center;
  padding: 8px 16px;
  background: rgba(255,255,255,0.9);
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(120,80,160,0.15);
}

.diff-label {
  font-weight: 700;
  margin: 0 6px 0 0;
  font-size: 0.95rem;
  vertical-align: middle;
}

.diff-btn {
  display: inline-block;
  margin: 2px 4px;
  padding: 6px 14px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 2px 6px rgba(120,80,160,0.18);
}
.diff-btn.active {
  background: var(--purple);
  color: #fff;
}

.card-grid {
  display: grid;
  gap: 8px;
  max-width: min(600px, 94vw);
  justify-content: center;
}
.card-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.card-container {
  perspective: 600px;
}

.card {
  position: relative;
  width: clamp(70px, 18vw, 120px);
  height: clamp(70px, 18vw, 120px);
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
}
.card.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  box-shadow: 0 6px 16px rgba(120,80,160,0.2);
  font-size: clamp(2rem, 7vw, 3.5rem);
}
.card-front {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: #fff;
  font-size: clamp(1.8rem, 6vw, 3rem);
  font-weight: 800;
}
.card-back {
  background: #fff;
  transform: rotateY(180deg);
  border: 4px solid #eee;
}
.card.matched .card-back {
  border-color: var(--green);
  box-shadow: 0 0 16px rgba(95,211,95,0.4);
}

.progress-wrap {
  width: 100%;
  max-width: 400px;
  height: 10px;
  background: rgba(255,255,255,0.6);
  border-radius: 999px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  transition: width 0.35s ease;
}

.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(60,44,90,0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.win-overlay.open { display: flex; }

.win-modal {
  background: var(--panel);
  border-radius: 24px;
  padding: 24px;
  width: min(400px, 94vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(60,44,90,0.4);
  animation: popin 0.25s ease;
}
@keyframes popin {
  from { transform: scale(0.85); opacity: 0; }
}

.win-modal .trophy {
  font-size: 4.6rem;
  animation: bounce 0.8s ease infinite alternate;
}
@keyframes bounce { to { transform: translateY(-14px); } }

.win-modal h2 {
  margin: 0 0 4px;
  font-size: 1.8rem;
}
.win-modal .stars-row {
  font-size: 2.4rem;
  letter-spacing: 6px;
  margin: 6px 0 12px;
}
.win-modal .win-stat {
  font-weight: 700;
  opacity: 0.8;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 95;
  pointer-events: none;
}

@media (max-width: 680px) {
  .site-logo { gap: 6px; font-size: 0.82rem; }
  .site-logo-mark { width: 30px; height: 30px; font-size: 0.66rem; }
  .logo { font-size: 1rem; max-width: 34vw; }
}

@media (max-width: 430px) {
  .chip { display: none; }
  .card { width: clamp(60px, 22vw, 80px); height: clamp(60px, 22vw, 80px); }
}
