/* ═══════════════════════════════════════════════════════════════════
   MIA GAMES — Memory Match Game Styles
   File     : games/memory-match/memory.css
   Inherits : ../../style.css (global tokens + layout)

   TABLE OF CONTENTS
   ─────────────────
   01. Breadcrumb & Utilities
   02. Game Area Override
   03. Card Grid Layout
   04. Card — Structure & 3D Flip
   05. Card — States (flipped, matched, wrong)
   06. Card — Symbol Display
   07. Win Celebration Overlay
   08. Score Bump Animation
   09. SEO Article Content
   10. Responsive Breakpoints
   ═══════════════════════════════════════════════════════════════════ */


/* ═══════════════════════════════════════════════════════════════════
   01. BREADCRUMB & UTILITIES
   ═══════════════════════════════════════════════════════════════════ */

.breadcrumb-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.625rem 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.breadcrumb li { font-size: var(--fs-sm); color: var(--text-muted); }
.breadcrumb a  { color: var(--text-muted); text-decoration: none; transition: color var(--transition-fast); }
.breadcrumb a:hover { color: var(--accent-purple); }
.breadcrumb [aria-current="page"] { color: var(--text-secondary); font-weight: var(--fw-medium); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}


/* ═══════════════════════════════════════════════════════════════════
   02. GAME AREA OVERRIDE
   ═══════════════════════════════════════════════════════════════════ */

.memory-game-area {
  /* Override global min-height — grid height determines the height */
  min-height: unset;
  padding: var(--space-6);
  gap: var(--space-4);
  /* Allow grid to expand freely */
  align-items: center;
}


/* ═══════════════════════════════════════════════════════════════════
   03. CARD GRID LAYOUT
   ═══════════════════════════════════════════════════════════════════ */

.memory-grid {
  display: grid;
  gap: 10px;
  width: 100%;
  /* grid-template-columns is set dynamically by JS via inline style */
  justify-content: center;
}

/*
 * Grid column counts are applied by JS as inline style:
 *   4×4 → grid-template-columns: repeat(4, 1fr)
 *   6×6 → grid-template-columns: repeat(6, 1fr)
 *
 * Max-widths ensure cards don't get too large on wide screens.
 */
.memory-grid.grid-4 { max-width: 420px; }
.memory-grid.grid-6 { max-width: 560px; }


/* ═══════════════════════════════════════════════════════════════════
   04. CARD — STRUCTURE & 3D FLIP
   ═══════════════════════════════════════════════════════════════════

   Each card is built with three nested elements:

   .memory-card          — outer wrapper, sets dimensions, holds perspective
     └── .card-inner     — the element that physically rotates 180°
           ├── .card-face.card-front   — the face-down back design
           └── .card-face.card-back    — the face-up emoji symbol

   The 3D flip uses CSS `transform-style: preserve-3d` on .card-inner
   and `backface-visibility: hidden` on both faces.
   When .memory-card.is-flipped is applied, .card-inner rotates 180°,
   which hides .card-front (now facing away) and reveals .card-back.
   ═══════════════════════════════════════════════════════════════════ */

.memory-card {
  /* Establish perspective for 3D child transforms */
  perspective: 600px;

  /* Aspect ratio 1:1 keeps cards square regardless of column width */
  aspect-ratio: 1 / 1;

  cursor: pointer;
  position: relative;

  /* Prevent layout shift during animation */
  transform-origin: center center;

  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.memory-card:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 3px;
  border-radius: var(--radius-md);
}

/* The rotating inner element */
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;

  /* Enable 3D space for children */
  transform-style: preserve-3d;

  /* Smooth flip transition */
  transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1);

  border-radius: var(--radius-md);
}

/* Flipped state — rotates the inner 180° around Y axis */
.memory-card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

/* Both faces share base positioning */
.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;

  /* Each face is hidden when it faces away from viewer */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;

  overflow: hidden;
}

/* ── CARD FRONT (face-down back) ────────────────────────────────── */
.card-front {
  background: var(--bg-tertiary);
  border: 2px solid var(--border-default);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

/* Decorative pattern on the card back */
.card-front::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: calc(var(--radius-md) - 3px);
  border: 1.5px solid var(--border-subtle);
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    var(--border-subtle) 4px,
    var(--border-subtle) 5px
  );
  opacity: 0.5;
}

/* MIA logo mark on face-down card */
.card-front::after {
  content: '🎮';
  font-size: clamp(1rem, 4vw, 1.5rem);
  opacity: 0.25;
  position: relative;
  z-index: 1;
}

/* Hover — only on unflipped, unmatched cards */
.memory-card:not(.is-flipped):not(.is-matched):hover .card-front {
  background: var(--bg-surface);
  border-color: var(--accent-purple);
}

/* ── CARD BACK (face-up symbol) ─────────────────────────────────── */
.card-back {
  background: var(--gradient-card);
  border: 2px solid var(--border-default);

  /* The face-up side starts rotated 180° — it only shows when
     the parent .card-inner has also rotated 180° */
  transform: rotateY(180deg);

  transition: background var(--transition-fast), border-color var(--transition-fast);
}


/* ═══════════════════════════════════════════════════════════════════
   05. CARD — STATES
   ═══════════════════════════════════════════════════════════════════ */

/* ── Matched ── */
.memory-card.is-matched .card-back {
  background: var(--accent-teal-dim);
  border-color: var(--accent-teal);
  box-shadow: 0 0 16px rgba(62, 207, 207, 0.25);
}

.memory-card.is-matched {
  cursor: default;
  animation: matchPop 0.4s var(--ease-spring) both;
}

@keyframes matchPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.12); }
  70%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* ── Wrong guess flash ── */
.memory-card.is-wrong .card-back {
  background: var(--accent-red-dim);
  border-color: var(--accent-red);
  animation: wrongShake 0.4s ease both;
}

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

/* ── Card deal entrance ── */
.memory-card.card-deal {
  animation: cardDeal 0.35s var(--ease-spring) both;
}

@keyframes cardDeal {
  from { opacity: 0; transform: scale(0.7) rotate(-4deg); }
  to   { opacity: 1; transform: scale(1)   rotate(0deg); }
}


/* ═══════════════════════════════════════════════════════════════════
   06. CARD — SYMBOL DISPLAY
   ═══════════════════════════════════════════════════════════════════ */

.card-symbol {
  /* Emoji scales with card size using clamp() */
  font-size: clamp(1.25rem, 5vw, 2rem);
  line-height: 1;
  display: block;

  /* Subtle entrance scale when card flips */
  transition: transform 0.2s var(--ease-spring);
}

.memory-card.is-flipped .card-symbol {
  transform: scale(1);
}

/* Match shimmer — runs on matched cards */
.memory-card.is-matched .card-symbol {
  animation: symbolShimmer 0.6s ease both;
}

@keyframes symbolShimmer {
  0%   { transform: scale(1)    rotate(0deg); }
  30%  { transform: scale(1.25) rotate(-8deg); }
  60%  { transform: scale(1.1)  rotate(5deg); }
  100% { transform: scale(1)    rotate(0deg); }
}


/* ═══════════════════════════════════════════════════════════════════
   07. WIN CELEBRATION OVERLAY
   ═══════════════════════════════════════════════════════════════════ */

.memory-win-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 13, 26, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

[data-theme="light"] .memory-win-overlay {
  background: rgba(245, 245, 252, 0.85);
}

.memory-win-overlay.is-visible {
  opacity: 1;
  pointer-events: all;
}

.memory-win-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: clamp(2rem, 5vw, 3rem) clamp(2rem, 6vw, 4rem);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: calc(100% - 2rem);
  animation: winBoxPop 0.5s var(--ease-spring) both;
}

@keyframes winBoxPop {
  from { transform: scale(0.7) translateY(30px); opacity: 0; }
  to   { transform: scale(1)   translateY(0);    opacity: 1; }
}

.win-trophy {
  font-size: 3.5rem;
  line-height: 1;
  animation: trophyBounce 0.8s var(--ease-spring) 0.3s both;
}

@keyframes trophyBounce {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  70%  { transform: scale(1.2) rotate(5deg); opacity: 1; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

.win-title {
  font-family: var(--font-display);
  font-size: clamp(var(--fs-xl), 4vw, var(--fs-3xl));
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  letter-spacing: var(--ls-snug);
  margin: 0;
}

.win-sub {
  font-size: var(--fs-base);
  color: var(--text-secondary);
  margin: 0;
  max-width: 28ch;
  line-height: 1.6;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  width: 100%;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.win-stat-value {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--accent-teal);
  line-height: 1;
}

.win-stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
}

.win-new-best {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--accent-amber-dim);
  border: 1px solid var(--accent-amber);
  border-radius: var(--radius-full);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--accent-amber);
  animation: badgePop 0.4s var(--ease-spring) 0.6s both;
}

@keyframes badgePop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.win-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}


/* ═══════════════════════════════════════════════════════════════════
   08. SCORE BUMP ANIMATION
   ═══════════════════════════════════════════════════════════════════ */

.score-bump {
  animation: scoreBump 0.35s var(--ease-spring) both;
}

@keyframes scoreBump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.5); color: var(--accent-teal); }
  100% { transform: scale(1); }
}


/* ═══════════════════════════════════════════════════════════════════
   09. SEO ARTICLE CONTENT
   ═══════════════════════════════════════════════════════════════════ */

.seo-content {
  padding: 2.5rem 0 1rem;
  border-top: 1px solid var(--border-subtle);
}

.seo-content h2 {
  font-size: clamp(var(--fs-xl), 2.5vw, var(--fs-2xl));
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.seo-content h3 {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin-top: 1.75rem;
  margin-bottom: 0.6rem;
}

.seo-content p {
  font-size: var(--fs-base);
  color: var(--text-secondary);
  line-height: 1.85;
  max-width: none;
  margin-bottom: 1rem;
}

.seo-content ul {
  padding-left: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.seo-content ul li {
  list-style: disc;
  font-size: var(--fs-base);
  color: var(--text-secondary);
  line-height: 1.75;
}


/* ═══════════════════════════════════════════════════════════════════
   10. RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 768px) ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .memory-grid { gap: 8px; }
  .memory-grid.grid-4 { max-width: 340px; }
  .memory-grid.grid-6 { max-width: 100%; }
  .card-front::after { font-size: 1rem; }
  .win-stats { grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
}

/* ── Mobile (≤ 480px) ─────────────────────────────────────────── */
@media (max-width: 480px) {
  .memory-grid { gap: 6px; }
  .memory-grid.grid-4 { max-width: 300px; }
  .card-front::before { inset: 4px; }
  .card-symbol { font-size: 1.1rem; }
  .win-box { padding: 1.5rem; }
}

/* ── Very small (≤ 360px) ─────────────────────────────────────── */
@media (max-width: 360px) {
  .memory-grid { gap: 5px; }
  .card-symbol { font-size: 0.95rem; }
  .memory-game-area { padding: var(--space-4); }
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE CONTROLS FIX — Keep title and controls on one row
   ═══════════════════════════════════════════════════════════════════ */

.game-controls {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--space-2);
  width: 100%;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 48px;                 /* Consistent minimum height */
}

.game-controls-title {
  font-family: var(--font-display);
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  flex: 0 0 auto;
  white-space: nowrap;
  min-width: 0;
  line-height: 1.4;                /* Consistent line height */
}

.game-controls-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
  height: 100%;                   /* Match parent height */
}

.game-controls-right .difficulty-select {
  flex: 0 1 auto;
  min-width: 75px;
  max-width: 110px;
  padding: var(--space-1) var(--space-6) var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
  height: 32px;                   /* Fixed height */
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239898b8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  box-sizing: border-box;
}

.game-controls-right .control-btn {
  flex: 0 0 auto;
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
  min-height: 32px;               /* Consistent height */
  min-width: 32px;                /* Consistent width */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  box-sizing: border-box;
}

.game-controls-right .control-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-strong);
}

.game-controls-right .control-btn.control-btn--primary {
  background: var(--accent-purple);
  color: #fff;
  border-color: var(--accent-purple);
}

.game-controls-right .control-btn.control-btn--primary:hover {
  background: var(--accent-purple-dim);
  border-color: var(--border-accent);
}

.game-controls-right .control-btn .btn-text {
  display: inline;
}

/* ── Mobile responsive ── */
@media (max-width: 480px) {
  .game-controls {
    gap: var(--space-1);
    padding-bottom: var(--space-2);
    flex-wrap: nowrap;
  }

  .game-controls-title {
    font-size: var(--fs-sm);
    flex: 0 0 auto;
    max-width: 35%;      /* Reduced from 50% */
  }

  .game-controls-right {
    gap: var(--space-1);
    flex: 1 1 auto;
  }

  .game-controls-right .difficulty-select {
    min-width: 60px;      /* Increased from 45px */
    max-width: 85px;      /* Increased from 70px */
    font-size: 0.65rem;
    padding: var(--space-1) var(--space-4) var(--space-1) var(--space-1);
    padding-right: 20px;
    background-position: right 5px center;
    background-size: 8px 5px;
    height: 28px;
  }

  .game-controls-right .control-btn {
    padding: var(--space-1) var(--space-2);
    font-size: 0.65rem;
    min-height: 28px;
    min-width: 28px;
  }

  .game-controls-right .control-btn svg {
    width: 12px;
    height: 12px;
  }

  .game-controls-right .control-btn .btn-text {
    display: none;
  }

  .game-controls-right .control-btn.control-btn--primary .btn-text {
    display: inline;
    font-size: 0.65rem;
  }
}

@media (max-width: 380px) {
  .game-controls-title {
    font-size: 0.7rem;
    max-width: 30%;
  }

  .game-controls-right .difficulty-select {
    min-width: 50px;
    max-width: 70px;
    font-size: 0.6rem;
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
    padding-right: 16px;
    background-size: 6px 4px;
    background-position: right 4px center;
    height: 24px;
  }

  .game-controls-right .control-btn {
    padding: var(--space-1);
    min-height: 24px;
    min-width: 24px;
  }

  .game-controls-right .control-btn svg {
    width: 10px;
    height: 10px;
  }

  .game-controls-right .control-btn .btn-text {
    display: none !important;
  }

  .game-controls-right .control-btn.control-btn--primary .btn-text {
    display: none !important;
  }
}

/* ── Mobile Click Fix ── */
button,
a,
.control-btn,
.primary-btn,
.secondary-btn,
.nav-toggle,
.theme-toggle,
.play-btn,
.game-card-link,
.game-card a,
.difficulty-select,
.memory-card {
  pointer-events: auto !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent !important;
  cursor: pointer !important;
}

.nav-overlay {
  pointer-events: none !important;
}
.nav-overlay.is-visible {
  pointer-events: auto !important;
}

.mobile-nav a {
  pointer-events: auto !important;
  touch-action: manipulation !important;
}

.ad-container,
.ad-placeholder,
.adsbygoogle {
  pointer-events: none !important;
}
.ad-container .adsbygoogle {
  pointer-events: auto !important;
}

/* ── Stats Row ── */
.game-stats-row {
  display: flex;
  justify-content: space-around;
  width: 100%;
  padding: var(--space-3) 0;
  gap: var(--space-2);
}

.game-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.game-stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  font-weight: var(--fw-medium);
}

.game-stat-value {
  font-family: var(--font-display);
  font-size: var(--fs-xl);          /* Default desktop size */
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  line-height: 1.2;
}

/* ── Responsive Stats ── */
@media (max-width: 768px) {
  .game-stat-value {
    font-size: var(--fs-lg);        /* Slightly smaller on tablet */
  }
}

@media (max-width: 480px) {
  .game-stat-value {
    font-size: var(--fs-base);      /* Even smaller on mobile */
  }
}

@media (max-width: 360px) {
  .game-stat-value {
    font-size: var(--fs-sm);        /* Smallest on very small screens */
  }
}

/* ── Status Message ── */
.game-status {
  font-size: var(--fs-base);
  color: var(--text-secondary);
  text-align: center;
  margin: 0;
  padding: var(--space-2) 0;
  min-height: 2.5rem;
  line-height: 1.5;
}

/* ── Responsive Status ── */
@media (max-width: 768px) {
  .game-status {
    font-size: var(--fs-sm);
  }
}

@media (max-width: 480px) {
  .game-status {
    font-size: var(--fs-xs);
    min-height: 2rem;
    padding: var(--space-1) 0;
  }
}

@media (max-width: 360px) {
  .game-status {
    font-size: 0.65rem;
    min-height: 1.5rem;
  }
}