/* ==========================================
   MEMORY GAME — Responsive No-Scroll Layout
========================================== */

/* --- Keyframe Animations --- */

@keyframes vanish-effect {
  0%   { opacity: 1; transform: scale(1);    filter: brightness(1) saturate(1); }
  35%  { opacity: 1; transform: scale(1.1);  filter: brightness(2) saturate(2); }
  100% { opacity: 0; transform: scale(0.72); filter: brightness(2.5); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  15%       { transform: translateX(-7px) rotate(-1.5deg); }
  30%       { transform: translateX(7px)  rotate(1.5deg); }
  45%       { transform: translateX(-5px) rotate(-0.8deg); }
  60%       { transform: translateX(5px)  rotate(0.8deg); }
  75%       { transform: translateX(-3px); }
  90%       { transform: translateX(3px); }
}

@keyframes card-appear {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}


/* ==========================================
   GRID
========================================== */

#memory-grid {
  display: grid;
  gap: 8px;
  /* grid-template-columns and .memory-card heights are set by JS */
}


/* ==========================================
   CARD CONTAINER
========================================== */

.memory-card {
  position: relative;
  perspective: 1200px;
  cursor: pointer;
  /* height is injected via inline style by layoutCards() */
  animation: card-appear 0.25s ease both;
}

/* Staggered entry on siblings (up to 24 cards) */
.memory-card:nth-child(1)  { animation-delay:  0.00s; }
.memory-card:nth-child(2)  { animation-delay:  0.02s; }
.memory-card:nth-child(3)  { animation-delay:  0.04s; }
.memory-card:nth-child(4)  { animation-delay:  0.06s; }
.memory-card:nth-child(5)  { animation-delay:  0.08s; }
.memory-card:nth-child(6)  { animation-delay:  0.10s; }
.memory-card:nth-child(7)  { animation-delay:  0.12s; }
.memory-card:nth-child(8)  { animation-delay:  0.14s; }
.memory-card:nth-child(9)  { animation-delay:  0.16s; }
.memory-card:nth-child(10) { animation-delay:  0.18s; }
.memory-card:nth-child(11) { animation-delay:  0.20s; }
.memory-card:nth-child(12) { animation-delay:  0.22s; }
.memory-card:nth-child(13) { animation-delay:  0.24s; }
.memory-card:nth-child(14) { animation-delay:  0.26s; }
.memory-card:nth-child(15) { animation-delay:  0.28s; }
.memory-card:nth-child(16) { animation-delay:  0.30s; }
.memory-card:nth-child(17) { animation-delay:  0.32s; }
.memory-card:nth-child(18) { animation-delay:  0.34s; }
.memory-card:nth-child(19) { animation-delay:  0.36s; }
.memory-card:nth-child(20) { animation-delay:  0.38s; }
.memory-card:nth-child(21) { animation-delay:  0.40s; }
.memory-card:nth-child(22) { animation-delay:  0.42s; }
.memory-card:nth-child(23) { animation-delay:  0.44s; }
.memory-card:nth-child(24) { animation-delay:  0.46s; }

.memory-card:not(.is-flipped):not(.is-matched):hover {
  transform: translateY(-2px) scale(1.03);
  transition: transform 0.15s ease;
}


/* ==========================================
   CARD INNER — the 3-D flip wrapper
========================================== */

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
  border-radius: 12px;
}

/* Flip state: moves transform to .card-inner so hover on parent is unaffected */
.memory-card.is-flipped .card-inner {
  transform: rotateY(180deg);
}


/* ==========================================
   CARD FACES — shared
========================================== */

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}


/* ==========================================
   FRONT FACE  (face-down — user sees this)
========================================== */

.card-front {
  background: linear-gradient(
    145deg,
    #1a1744 0%,
    #2e2a7a 45%,
    #1a3470 100%
  );
  border: 2px solid rgba(99, 102, 241, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

/* Subtle radial shimmer */
.card-front::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at 35% 28%,
    rgba(165, 180, 252, 0.16) 0%,
    transparent 65%
  );
  pointer-events: none;
}

/* Grid pattern overlay */
.card-front::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(99, 102, 241, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 102, 241, 0.06) 1px, transparent 1px);
  background-size: 18px 18px;
  pointer-events: none;
}

.card-front-icon {
  position: relative; /* above ::after overlay */
  z-index: 1;
  width: 36%;
  height: 36%;
  color: rgba(165, 180, 252, 0.82);
  filter: drop-shadow(0 0 10px rgba(129, 140, 248, 0.65));
}


/* ==========================================
   BACK FACE  (face-up — image + word)
========================================== */

.card-back {
  background: #08101e;
  border: 2px solid rgba(6, 182, 212, 0.5);
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  box-shadow:
    0 0 24px rgba(6, 182, 212, 0.22),
    0 6px 22px rgba(0, 0, 0, 0.55);
}

.card-back-image {
  flex: 1;
  width: 100%;
  display: block;
  object-fit: cover;
  min-height: 0; /* required for flex shrink in Safari */
}

.card-back-text-container {
  flex-shrink: 0;
  padding: 3px 6px 4px;
  background: rgba(2, 6, 20, 0.97);
  text-align: center;
  border-top: 1px solid rgba(6, 182, 212, 0.28);
}

.card-back-word {
  display: block;
  font-size: clamp(0.55rem, 1.3vw, 0.72rem);
  font-weight: 700;
  color: #e2e8f0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-back-translation {
  display: block;
  font-size: clamp(0.48rem, 1.05vw, 0.6rem);
  font-style: italic;
  color: #22d3ee;
  line-height: 1.2;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ==========================================
   STATE: MATCHED
========================================== */

.memory-card.is-matched {
  cursor: default;
  pointer-events: none;
  animation: vanish-effect 0.55s ease-in 0.3s forwards;
}


/* ==========================================
   STATE: SHAKE (mismatch)
========================================== */

.memory-card.shake {
  animation: shake 0.5s ease-in-out;
}


/* ==========================================
   RESPONSIVE TWEAKS
========================================== */

@media (max-width: 640px) {
  #memory-grid {
    gap: 6px;
  }

  .card-face,
  .card-inner {
    border-radius: 9px;
  }

  .card-back-text-container {
    padding: 2px 4px 3px;
  }
}

@media (max-width: 380px) {
  #memory-grid {
    gap: 5px;
  }
}