/* ================================================================
   Bug Match — CSS
   A nature-themed memory game for kids
   ================================================================ */

/* ── Fonts & CSS Variables ── */
@import url('https://fonts.googleapis.com/css2?family=Bubblegum+Sans&family=Outfit:wght@400;600;700;900&display=swap');

:root {
  --bm-green-dark:    #1a4a1a;
  --bm-green-mid:     #2d7a2d;
  --bm-green-light:   #4aad4a;
  --bm-green-bright:  #6fce6f;
  --bm-leaf-front:    #3a8c3a;
  --bm-leaf-back:     #2d6a2d;
  --bm-soil:          #4a2800;
  --bm-cream:         #fdf6e3;
  --bm-gold:          #f5c842;
  --bm-gold-dark:     #d4a017;
  --bm-card-radius:   16px;
  --bm-flip-speed:    0.5s;
}

/* ── Base / Body ── */
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Outfit', sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(106, 210, 106, 0.35), transparent),
    linear-gradient(180deg, #0d2b0d 0%, #1b4a1b 30%, #2a6e2a 70%, #1a3d1a 100%);
  overflow-x: hidden;
}

/* ── Ambient Floating Bugs ── */
#ambientBugs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.ambient-bug {
  position: absolute;
  font-size: 1.4rem;
  opacity: 0.18;
  animation: ambientDrift linear infinite;
  user-select: none;
}

@keyframes ambientDrift {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.18; }
  90%  { opacity: 0.18; }
  100% { transform: translate(var(--drift-x), var(--drift-y)) rotate(var(--drift-r)); opacity: 0; }
}

/* ── Header ── */
.bm-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(111, 206, 111, 0.2);
  gap: 12px;
  flex-wrap: wrap;
}

.bm-sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.bm-sound-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.08);
}

.bm-sound-btn.muted {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.bm-header-center {
  display: flex;
  align-items: center;
  gap: 10px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.bm-header-icon {
  font-size: 1.8rem;
  animation: headerBugWiggle 3s ease-in-out infinite;
}

@keyframes headerBugWiggle {
  0%, 100% { transform: rotate(0deg); }
  20%       { transform: rotate(-12deg); }
  40%       { transform: rotate(10deg); }
  60%       { transform: rotate(-8deg); }
  80%       { transform: rotate(6deg); }
}

.bm-header-title {
  font-family: 'Bubblegum Sans', 'Outfit', sans-serif;
  font-size: 1.6rem;
  color: #a8f0a8;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.02em;
}

.bm-scoreboard-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-top: 20px;
  margin-bottom: 10px;
}

.bm-scoreboard {
  display: flex;
  gap: 16px;
  background: rgba(0, 0, 0, 0.25);
  padding: 10px 20px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.bm-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 6px 14px;
  min-width: 60px;
}

.bm-stat-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.bm-stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: #a8f0a8;
  font-variant-numeric: tabular-nums;
}

/* ── 2 Player Panels ── */
.bm-player-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 6px 14px 6px 6px;
  opacity: 0.5;
  transition: all 0.3s ease;
}

.bm-player-panel.active-turn {
  opacity: 1;
  background: rgba(111, 206, 111, 0.15);
  border-color: #6fce6f;
  box-shadow: 0 0 15px rgba(111, 206, 111, 0.2);
  transform: scale(1.05);
}

.bm-player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
}

#panelP1 .bm-player-avatar { background: #4f46e5; }
#panelP2 .bm-player-avatar { background: #e11d48; }

.bm-player-info {
  display: flex;
  flex-direction: column;
}

.bm-player-name {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.6);
}

.active-turn .bm-player-name {
  color: #a8f0a8;
}

.bm-player-score {
  font-size: 1.2rem;
  font-weight: 900;
  color: #fff;
  line-height: 1;
}

/* ── Utilities ── */
.hidden {
  display: none !important;
}

/* ── Screens ── */
.bm-screen {
  display: none;
  position: relative;
  z-index: 5;
  min-height: calc(100vh - 64px);
  padding: 24px 16px 40px;
}

.bm-screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── Menu ── */
.bm-menu {
  background: rgba(18, 38, 22, 0.95);
  backdrop-filter: blur(16px);
  padding: 40px 50px;
  border-radius: 24px;
  text-align: center;
  border: 1px solid rgba(111, 206, 111, 0.3);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(111, 206, 111, 0.15);
  position: relative;
  overflow: hidden;
  max-width: 520px;
  width: 100%;
}

/* Floating bugs decorating the menu card */
.bm-menu-bugs {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 28px;
  overflow: hidden;
}

.bm-menu-bug {
  position: absolute;
  font-size: 1.5rem;
  opacity: 0.22;
  animation: menuBugFloat 4s ease-in-out infinite;
}

.bm-menu-bug--1 { top: 8%;  left: 8%;  animation-delay: 0s;    animation-duration: 3.5s; }
.bm-menu-bug--2 { top: 6%;  right: 10%; animation-delay: 0.5s;  animation-duration: 4.2s; }
.bm-menu-bug--3 { bottom: 12%; left: 6%; animation-delay: 1s;    animation-duration: 3.8s; }
.bm-menu-bug--4 { bottom: 8%; right: 8%; animation-delay: 0.3s;  animation-duration: 4.5s; }
.bm-menu-bug--5 { top: 40%;  left: 4%;  animation-delay: 1.5s;  animation-duration: 3.2s; }
.bm-menu-bug--6 { top: 35%;  right: 4%; animation-delay: 0.8s;  animation-duration: 4.0s; }

@keyframes menuBugFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%       { transform: translateY(-8px) rotate(10deg); }
}

.bm-menu-title {
  font-family: 'Bubblegum Sans', 'Outfit', sans-serif;
  font-size: 2.8rem;
  color: #a8f0a8;
  margin: 0 0 8px;
  text-shadow: 0 0 30px rgba(111, 206, 111, 0.5), 0 3px 8px rgba(0,0,0,0.6);
}

.bm-menu-subtitle {
  color: rgba(255, 255, 255, 0.6);
  font-size: 1rem;
  margin: 0 0 32px;
}

.bm-difficulty-label {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 14px;
}

.bm-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.bm-diff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.bm-diff-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 16px 12px;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bm-diff-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-4px) scale(1.02);
}

.bm-diff-btn--selected {
  background: rgba(111, 206, 111, 0.15);
  border-color: #6fce6f;
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 16px rgba(111, 206, 111, 0.2);
}

.bm-diff-icon {
  font-size: 1.8rem;
}

.bm-diff-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.bm-diff-sub {
  font-size: 0.72rem;
  opacity: 0.7;
}

/* ── Start Button ── */
.bm-start-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 36px;
  background: linear-gradient(135deg, #4aad4a, #2d7a2d);
  border: none;
  border-radius: 100px;
  color: #fff;
  font-family: 'Bubblegum Sans', 'Outfit', sans-serif;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow:
    0 6px 20px rgba(74, 173, 74, 0.45),
    inset 0 1px 0 rgba(255,255,255,0.2);
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  letter-spacing: 0.02em;
  width: 100%;
}

.bm-start-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(74, 173, 74, 0.6);
  background: linear-gradient(135deg, #5dbd5d, #3a8c3a);
}

.bm-start-btn:active {
  transform: translateY(0);
}

/* ── Game Board ── */
.bm-game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  width: 100%;
}

.bm-board {
  display: grid;
  gap: 12px;
  /* columns set by JS */
}

/* ── Memory Card ── */
.bm-card {
  width: 100px;
  height: 100px;
  cursor: pointer;
  perspective: 800px;
  position: relative;
}

.bm-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--bm-flip-speed) cubic-bezier(0.4, 0.2, 0.2, 1);
  border-radius: var(--bm-card-radius);
}

.bm-card.flipped .bm-card-inner,
.bm-card.matched .bm-card-inner {
  transform: rotateY(180deg);
}

/* Card face (leaf back) */
.bm-card-front,
.bm-card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--bm-card-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The leaf face (what you see before flipping) */
.bm-card-front {
  background: radial-gradient(circle at 40% 35%, #5dbd5d, #2d7a2d);
  border: 2px solid rgba(111, 206, 111, 0.5);
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.bm-card-front::before {
  /* Leaf vein */
  content: '';
  position: absolute;
  width: 3px;
  height: 65%;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  top: 17%;
  left: 50%;
  transform: translateX(-50%);
}

.bm-card-front::after {
  /* Leaf shine */
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  background: radial-gradient(circle, rgba(255,255,255,0.25), transparent);
  top: 10%;
  left: 15%;
  border-radius: 50%;
}

.bm-leaf-icon {
  font-size: 2.4rem;
  opacity: 0.6;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

/* The bug face (revealed on flip) */
.bm-card-back {
  background: radial-gradient(circle at 40% 30%, #fefdf8, #f0eddc);
  border: 2px solid rgba(200, 180, 100, 0.5);
  transform: rotateY(180deg);
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.bm-bug-emoji {
  font-size: 2.8rem;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
  transition: transform 0.2s ease;
}

/* Match state */
.bm-card.matched .bm-card-front {
  background: radial-gradient(circle at 40% 35%, #8adb8a, #4aad4a);
}

.bm-card.matched .bm-card-back {
  background: radial-gradient(circle at 40% 30%, #fffbe8, #fff8d6);
  border-color: rgba(245, 200, 66, 0.7);
  box-shadow:
    0 0 0 3px rgba(245, 200, 66, 0.5),
    0 6px 24px rgba(245, 200, 66, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.bm-card.matched .bm-bug-emoji {
  animation: bugMatchBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bugMatchBounce {
  0%   { transform: scale(0.7) rotate(-15deg); }
  60%  { transform: scale(1.3) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Wrong attempt shake */
.bm-card.wrong .bm-card-inner {
  animation: cardWrongShake 0.4s ease;
}

@keyframes cardWrongShake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20%       { transform: rotateY(180deg) translateX(-6px); }
  40%       { transform: rotateY(180deg) translateX(6px); }
  60%       { transform: rotateY(180deg) translateX(-4px); }
  80%       { transform: rotateY(180deg) translateX(4px); }
}

/* Hover on card */
.bm-card:not(.flipped):not(.matched):hover .bm-card-inner {
  transform: rotateY(15deg) scale(1.04);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

/* ── Game Bottom Controls ── */
.bm-game-bottom {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 16px 0 8px;
  flex-wrap: wrap;
}

.bm-action-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 14px 24px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.bm-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.bm-action-btn--menu {
  background: rgba(74, 173, 74, 0.12);
  border-color: rgba(111, 206, 111, 0.3);
  color: #a8f0a8;
}

.bm-action-btn--menu:hover {
  background: rgba(74, 173, 74, 0.25);
  color: #c8f5c8;
}

/* ── Win Overlay ── */
.bm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  animation: overlayFadeIn 0.4s ease;
}

.bm-overlay.hidden {
  display: none;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.bm-overlay-content {
  background: rgba(10, 40, 10, 0.92);
  border: 1px solid rgba(111, 206, 111, 0.35);
  border-radius: 28px;
  padding: 48px 40px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow:
    0 40px 100px rgba(0, 0, 0, 0.6),
    0 0 60px rgba(111, 206, 111, 0.15),
    inset 0 1px 0 rgba(255,255,255,0.08);
  animation: overlaySlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes overlaySlideIn {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.bm-win-bugs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
  font-size: 2rem;
}

.bm-win-bugs span {
  animation: winBugPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

.bm-win-bugs span:nth-child(1) { animation-delay: 0.05s; }
.bm-win-bugs span:nth-child(2) { animation-delay: 0.10s; }
.bm-win-bugs span:nth-child(3) { animation-delay: 0.15s; }
.bm-win-bugs span:nth-child(4) { animation-delay: 0.20s; }
.bm-win-bugs span:nth-child(5) { animation-delay: 0.25s; }
.bm-win-bugs span:nth-child(6) { animation-delay: 0.30s; }
.bm-win-bugs span:nth-child(7) { animation-delay: 0.35s; }
.bm-win-bugs span:nth-child(8) { animation-delay: 0.40s; }
.bm-win-bugs span:nth-child(9) { animation-delay: 0.45s; }

@keyframes winBugPop {
  from { transform: scale(0) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

.bm-win-title {
  font-family: 'Bubblegum Sans', 'Outfit', sans-serif;
  font-size: 2.4rem;
  color: #a8f0a8;
  margin: 0 0 8px;
  text-shadow: 0 0 30px rgba(111, 206, 111, 0.6);
}

.bm-win-sub {
  color: rgba(255, 255, 255, 0.55);
  font-size: 1rem;
  margin: 0 0 28px;
}

.bm-win-stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 28px;
}

.bm-win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 14px 20px;
  flex: 1;
}

.bm-win-stat-icon { font-size: 1.4rem; }
.bm-win-stat-val {
  font-size: 1.4rem;
  font-weight: 700;
  color: #a8f0a8;
  font-variant-numeric: tabular-nums;
}
.bm-win-stat-lbl {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
}

.bm-win-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Responsive: Smaller Screens ── */
@media (max-width: 600px) {
  .bm-header-center {
    position: static;
    transform: none;
    order: -1;
    width: 100%;
    justify-content: center;
  }

  .bm-header {
    flex-wrap: wrap;
    justify-content: center;
  }

  .bm-header-stats {
    width: 100%;
    justify-content: center;
    margin-left: 0;
  }

  .bm-card {
    width: 74px;
    height: 74px;
  }

  .bm-bug-emoji { font-size: 2rem; }
  .bm-leaf-icon { font-size: 1.8rem; }

  .bm-menu {
    padding: 36px 20px 28px;
  }

  .bm-menu-title {
    font-size: 2rem;
  }

  .bm-diff-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .bm-board {
    gap: 8px;
  }

  .bm-overlay-content {
    padding: 32px 20px;
  }

  .bm-win-stats {
    gap: 8px;
  }
}

@media (max-width: 400px) {
  .bm-card {
    width: 62px;
    height: 62px;
  }

  .bm-bug-emoji { font-size: 1.7rem; }
  .bm-leaf-icon { font-size: 1.5rem; }
}

/* ── Confetti particle (generated by JS) ── */
.bm-confetti {
  position: fixed;
  top: -20px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 200;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
