/* ===========================================
   FAMILY MATCH — Full Redesign
   Warm, playful, photo-forward
   =========================================== */

:root {
  --bg: #1a1028;
  --card-back: linear-gradient(145deg, #ff6b4a, #e83e8c);
  --card-back-pattern: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.15) 0%, transparent 50%);
  --accent: #ff6b4a;
  --accent-pink: #e83e8c;
  --gold: #ffd166;
  --green: #06d6a0;
  --surface: rgba(255,255,255,0.08);
  --text: #fff;
  --text-dim: rgba(255,255,255,0.6);
  --radius: 16px;
  --font: 'Fredoka', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ===========================================
   SHARED BUTTON
   =========================================== */
.btn {
  font-family: var(--font);
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn:active { transform: scale(0.95) !important; }

.btn-play {
  background: var(--card-back);
  color: #fff;
  font-size: 22px;
  padding: 18px 48px;
  border-radius: 60px;
  box-shadow: 0 8px 32px rgba(232,62,140,0.4), 0 0 0 0 rgba(255,107,74,0);
  animation: glow-pulse 2.5s ease-in-out infinite;
}

.btn-icon {
  font-size: 18px;
}

.btn-restart {
  background: rgba(255,255,255,0.12);
  color: var(--text);
  font-size: 16px;
  padding: 14px 36px;
  border-radius: 40px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.18);
}

/* ===========================================
   START SCREEN
   =========================================== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.start-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
}

.start-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
}

.start-bg-pattern {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(255,107,74,0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(232,62,140,0.2) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(255,209,102,0.08) 0%, transparent 60%);
}

.start-photos {
  display: flex;
  gap: 8px;
  margin-bottom: 32px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 320px;
}

.start-photo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  border: 3px solid rgba(255,255,255,0.25);
  animation: float-in 0.6s ease-out both;
}
.start-photo:nth-child(odd) { animation-delay: 0.1s; }
.start-photo:nth-child(even) { animation-delay: 0.25s; }

.start-title {
  font-size: 52px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #fff 0%, var(--gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.start-subtitle {
  font-size: 18px;
  color: var(--text-dim);
  margin-bottom: 40px;
  font-weight: 400;
}

/* ===========================================
   GAME SCREEN
   =========================================== */
.game-screen {
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.game-header {
  padding: 12px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}

.home-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  touch-action: manipulation;
}
.home-btn:active { transform: scale(0.9); }

.win-home-link {
  margin-top: 12px;
  color: var(--text-dim);
  font-size: 15px;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}
.win-home-link:hover { color: #fff; }

.game-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  width: 100px;
  height: 8px;
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 10px;
  transition: width 0.4s ease;
}

.progress-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 40px;
  text-align: right;
}

/* ===========================================
   SCROLLABLE GAME AREA
   =========================================== */
.game-scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ===========================================
   CARD GRID — 3 columns, fits one screen
   =========================================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 400px;
}

/* ===========================================
   3D FLIP CARD
   =========================================== */
.card-wrapper {
  perspective: 800px;
  aspect-ratio: 1;
  touch-action: manipulation;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-radius: var(--radius);
}

.card.flipped {
  transform: rotateY(180deg);
}

.card.matched {
  transform: rotateY(180deg);
}

.card.flipped .card-back,
.card.matched .card-back {
  visibility: hidden;
}

.card.matched .card-front {
  box-shadow: 0 0 0 3px var(--green), 0 0 24px rgba(6,214,160,0.35);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* BACK of card (question mark side — visible by default) */
.card-back {
  background: var(--card-back);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--card-back-pattern);
  border-radius: var(--radius);
}

.card-back-icon {
  font-size: 44px;
  position: relative;
  z-index: 1;
  opacity: 0.9;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
  font-weight: 700;
  color: rgba(255,255,255,0.85);
}

/* FRONT of card (photo side — hidden, rotated 180) */
.card-front {
  transform: rotateY(180deg);
  background: #1e1433;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: box-shadow 0.3s;
}

.card-photo {
  width: 100%;
  flex: 1;
  object-fit: cover;
  object-position: top center;
  display: block;
  image-rendering: auto;
}

.card-name {
  padding: 3px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #1e1433;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hover / tap feel */
@media (hover: hover) {
  .card-wrapper:hover .card:not(.flipped):not(.matched) {
    transform: scale(1.03);
  }
}
.card-wrapper:active .card:not(.flipped):not(.matched) {
  transform: scale(0.97);
}

/* Match celebration pulse */
.card.match-celebrate {
  animation: match-boom 0.5s ease;
}

/* ===========================================
   GAME FOOTER
   =========================================== */
.game-footer {
  padding: 10px 20px 16px;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

/* ===========================================
   WIN SCREEN
   =========================================== */
.win-screen {
  background: var(--bg);
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.win-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
}

.win-burst {
  position: absolute;
  width: 400px;
  height: 400px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  background: radial-gradient(circle, rgba(255,209,102,0.15) 0%, transparent 60%);
  z-index: -1;
  animation: burst-spin 8s linear infinite;
}

.win-emoji {
  font-size: 80px;
  margin-bottom: 16px;
  animation: bounce-in 0.6s ease-out;
}

.win-title {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.win-subtitle {
  font-size: 18px;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.family-parade {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 32px;
  max-width: 350px;
}

.parade-photo {
  width: 72px;
  height: 72px;
  object-fit: cover;
  object-position: top center;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: pop-in 0.4s ease-out both;
}
.parade-photo:nth-child(1) { animation-delay: 0.05s; }
.parade-photo:nth-child(2) { animation-delay: 0.1s; }
.parade-photo:nth-child(3) { animation-delay: 0.15s; }
.parade-photo:nth-child(4) { animation-delay: 0.2s; }
.parade-photo:nth-child(5) { animation-delay: 0.25s; }
.parade-photo:nth-child(6) { animation-delay: 0.3s; }
.parade-photo:nth-child(7) { animation-delay: 0.35s; }
.parade-photo:nth-child(8) { animation-delay: 0.4s; }
.parade-photo:nth-child(9) { animation-delay: 0.45s; }

/* ===========================================
   CONFETTI
   =========================================== */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1000;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0;
}

/* ===========================================
   ANIMATIONS
   =========================================== */
@keyframes glow-pulse {
  0%, 100% {
    box-shadow: 0 8px 32px rgba(232,62,140,0.4), 0 0 0 0 rgba(255,107,74,0);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 12px 40px rgba(232,62,140,0.5), 0 0 0 8px rgba(255,107,74,0.08);
    transform: scale(1.03);
  }
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes match-boom {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

@keyframes bounce-in {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes burst-spin {
  from { transform: translate(-50%, -60%) rotate(0deg); }
  to { transform: translate(-50%, -60%) rotate(360deg); }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-10px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ===========================================
   SCROLLBAR (minimal)
   =========================================== */
.game-scroll-area::-webkit-scrollbar {
  width: 4px;
}
.game-scroll-area::-webkit-scrollbar-track {
  background: transparent;
}
.game-scroll-area::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}
