/* ===========================================
   ANIMAL MATCH — Matching Family Match style
   =========================================== */

:root {
  --bg: #0f2027;
  --card-back: linear-gradient(145deg, #11998e, #38ef7d);
  --card-back-pattern: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.15) 0%, transparent 50%);
  --accent: #38ef7d;
  --accent-dark: #11998e;
  --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; }

/* ===========================================
   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: #0f2027;
  font-size: 22px;
  padding: 18px 48px;
  border-radius: 60px;
  box-shadow: 0 8px 32px rgba(56,239,125,0.3);
  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(56,239,125,0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(17,153,142,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(255,209,102,0.06) 0%, transparent 60%);
}

.start-emojis {
  font-size: 42px;
  margin-bottom: 28px;
  letter-spacing: 4px;
  animation: float-in 0.6s ease-out both;
}

.start-title {
  font-size: 52px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 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); }

.game-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  -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-dark), var(--accent));
  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
   =========================================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  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(--gold), 0 0 24px rgba(255,209,102,0.3);
}

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

.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;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.card-front {
  transform: rotateY(180deg);
  background: #132a2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: box-shadow 0.3s;
}

.card-emoji {
  font-size: 48px;
  line-height: 1;
}

.card-name {
  padding: 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.3px;
  margin-top: 4px;
}

@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);
}

.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(56,239,125,0.12) 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;
}

.animal-parade {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 32px;
  font-size: 48px;
}

.animal-parade span {
  animation: pop-in 0.4s ease-out both;
}
.animal-parade span:nth-child(1) { animation-delay: 0.05s; }
.animal-parade span:nth-child(2) { animation-delay: 0.1s; }
.animal-parade span:nth-child(3) { animation-delay: 0.15s; }
.animal-parade span:nth-child(4) { animation-delay: 0.2s; }
.animal-parade span:nth-child(5) { animation-delay: 0.25s; }
.animal-parade span:nth-child(6) { animation-delay: 0.3s; }

.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; }

/* ===========================================
   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(56,239,125,0.3);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 12px 40px rgba(56,239,125,0.4), 0 0 0 8px rgba(56,239,125,0.06);
    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
   =========================================== */
.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; }
