/* ===========================
   Al-Asmaa — Mini-Games Styles
   Premium "Sacred Arcade" design
   =========================== */

/* --- Page layout --- */
#pageMiniGames > .container {
  max-width: 640px;
  width: 100%;
  padding: 24px 16px;
}

/* ======================================================================
   HUB — Topbar Hero
   ====================================================================== */

.mg-topbar-hero {
  position: relative;
  overflow: hidden;
  padding: 20px 20px 0;
  margin: 0 0 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-card);
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(96, 165, 250, 0.05) 0%, transparent 100%),
    linear-gradient(180deg, rgba(96, 165, 250, 0.02) 0%, transparent 60%);
}
.mg-topbar-hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 5%;
  right: 5%;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(96, 165, 250, 0.2) 30%, rgba(96, 165, 250, 0.35) 50%, rgba(96, 165, 250, 0.2) 70%, transparent 100%);
}
.mg-topbar-ornament-tl,
.mg-topbar-ornament-br {
  position: absolute;
  width: 40px;
  height: 40px;
  pointer-events: none;
  z-index: 1;
  opacity: 0.12;
}
.mg-topbar-ornament-tl {
  top: 12px; left: 12px;
  border-top: 2px solid var(--sapphire);
  border-left: 2px solid var(--sapphire);
  border-radius: 6px 0 0 0;
}
.mg-topbar-ornament-br {
  bottom: 12px; right: 12px;
  border-bottom: 2px solid var(--sapphire);
  border-right: 2px solid var(--sapphire);
  border-radius: 0 0 6px 0;
}
.mg-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 0 18px;
  position: relative;
  z-index: 2;
}
.mg-topbar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(96, 165, 250, 0.10), transparent);
}
.mg-topbar-center { flex: 1; min-width: 0; }
.mg-topbar-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.01em;
  display: block;
}
.mg-topbar-subtitle {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.04em;
}
.mg-topbar-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--sapphire);
  letter-spacing: 0.04em;
  margin-left: auto;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: rgba(96, 165, 250, 0.06);
  border: 1px solid rgba(96, 165, 250, 0.15);
  flex-shrink: 0;
}
.mg-topbar-hero-body {
  text-align: center;
  padding: 24px 4px 32px;
  position: relative;
  z-index: 1;
}
.mg-topbar-hero-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.12) 0%, rgba(96, 165, 250, 0.04) 100%);
  border: 1.5px solid rgba(96, 165, 250, 0.22);
  box-shadow: 0 0 24px rgba(96, 165, 250, 0.08), 0 4px 12px rgba(0, 0, 0, 0.25);
  margin-bottom: 0.75rem;
  color: var(--sapphire);
}
.mg-topbar-hero-icon svg { width: 26px; height: 26px; }
.mg-topbar-hero-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.6rem;
  line-height: 1.35;
}
.mg-topbar-hero-sep {
  width: 40px;
  height: 2px;
  margin: 0 auto 0.6rem;
  background: linear-gradient(90deg, transparent, var(--sapphire), transparent);
  border-radius: 2px;
  opacity: 0.4;
}
.mg-topbar-hero-sub {
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.55;
  max-width: 380px;
  margin: 0 auto;
}

@media (min-width: 600px) {
  #pageMiniGames > .container {
    max-width: 640px;
    padding: 32px 24px;
  }
  .mg-topbar-hero {
    margin: 0;
    margin-bottom: 16px;
  }
}
@media (min-width: 768px) {
  #pageMiniGames > .container { max-width: 720px; }
  .mg-topbar-hero-title { font-size: 1.2rem; }
  .mg-topbar-hero-body { padding: 28px 8px 36px; }
}
@media (min-width: 1024px) {
  #pageMiniGames > .container { max-width: 780px; padding: 40px 32px; }
}
@media (min-width: 1280px) {
  #pageMiniGames > .container { max-width: 820px; padding: 48px 40px; }
}

/* Game cards — visual vertical cards */
.mg-hub {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding: 20px 0 40px;
}

.mg-hub-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translateY(16px);
  animation: mgFadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.mg-hub-card:nth-child(1) { animation-delay: 0.04s; }
.mg-hub-card:nth-child(2) { animation-delay: 0.1s; }
.mg-hub-card:nth-child(3) { animation-delay: 0.16s; }

/* Color per game */
.mg-hub-card[data-game="falling"]    { --mg-color: var(--gold); }
.mg-hub-card[data-game="memory"]     { --mg-color: var(--sapphire); }
.mg-hub-card[data-game="wordsearch"] { --mg-color: var(--emerald); }

/* Top visual banner area */
.mg-hub-banner {
  width: 100%;
  padding: 28px 16px 20px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 90% 80% at 50% 10%, color-mix(in srgb, var(--mg-color) 8%, transparent), transparent 70%),
    linear-gradient(180deg, rgba(15, 19, 36, 0.4) 0%, transparent 100%);
}

/* Shimmer line at top */
.mg-hub-banner::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--mg-color), transparent);
  opacity: 0.5;
  transition: opacity 0.3s;
}

.mg-hub-card:hover .mg-hub-banner::before {
  opacity: 1;
  animation: mgShimmer 2s ease infinite;
}

.mg-hub-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 16px;
  background: color-mix(in srgb, var(--mg-color) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--mg-color) 12%, transparent);
  color: var(--mg-color);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mg-hub-ico svg {
  width: 28px;
  height: 28px;
}

.mg-hub-card:hover .mg-hub-ico {
  transform: scale(1.12) translateY(-2px);
  background: color-mix(in srgb, var(--mg-color) 18%, transparent);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--mg-color) 15%, transparent);
}

/* Card body */
.mg-hub-body {
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.mg-hub-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.mg-hub-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.mg-hub-best {
  font-size: 0.72rem;
  color: var(--mg-color);
  font-weight: 600;
  margin-top: auto;
  padding-top: 4px;
}

.mg-hub-play {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 7px 20px;
  border: none;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--mg-color) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--mg-color) 15%, transparent);
  color: var(--mg-color);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.3px;
}

.mg-hub-play svg {
  width: 14px;
  height: 14px;
}

.mg-hub-card:hover .mg-hub-play {
  background: color-mix(in srgb, var(--mg-color) 20%, transparent);
  border-color: color-mix(in srgb, var(--mg-color) 30%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--mg-color) 10%, transparent);
}

/* Card hover */
.mg-hub-card:hover {
  border-color: color-mix(in srgb, var(--mg-color) 20%, transparent);
  transform: translateY(-4px);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.03),
    0 0 24px color-mix(in srgb, var(--mg-color) 6%, transparent);
}

.mg-hub-card:active {
  transform: scale(0.97) translateY(0);
  transition-duration: 0.1s;
}

@keyframes mgFadeInUp {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes mgShimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ======================================================================
   SHARED — Header, end screen, buttons
   ====================================================================== */

.mg-game-back {
  margin-bottom: 0;
}

.mg-game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(15, 19, 36, 0.9) 0%, rgba(10, 14, 28, 0.95) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  margin-bottom: 16px;
  gap: 14px;
  flex-wrap: wrap;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.mg-game-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--gold) 30%, rgba(212, 162, 76, 0.6) 50%, var(--gold) 70%, transparent 100%);
  background-size: 200% 100%;
  animation: mgShimmer 4s ease infinite;
}

.mg-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 0.88rem;
  color: var(--text-primary);
  font-weight: 600;
}

.mg-stat-label {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 0.78rem;
}

.mg-stat-value {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.mg-lives { display: flex; gap: 4px; }

.mg-heart {
  width: 18px; height: 18px;
  color: var(--ruby);
  transition: transform 0.3s, opacity 0.3s;
}

.mg-heart.lost {
  opacity: 0.15;
  transform: scale(0.7);
}

.mg-level-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: rgba(212, 162, 76, 0.1);
  border: 1px solid rgba(212, 162, 76, 0.15);
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-display);
}

/* --- Game wrapper (for overlay end screens) --- */
.mg-game-wrap {
  position: relative;
}

/* --- End screen overlay --- */
.mg-end-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 17, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 10;
  border-radius: var(--radius-lg);
  animation: mgFadeIn 0.4s ease;
  padding: 20px;
}

.mg-end-card {
  text-align: center;
  max-width: 310px;
  width: 100%;
  padding: 30px 24px;
  background: linear-gradient(160deg, rgba(12, 15, 30, 0.98) 0%, rgba(20, 26, 52, 0.95) 40%, rgba(15, 19, 36, 0.98) 100%);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.02) inset;
}

.mg-end-card::before {
  content: '';
  position: absolute;
  top: 10px; left: 10px;
  width: 22px; height: 22px;
  border-top: 1.5px solid rgba(212, 162, 76, 0.25);
  border-left: 1.5px solid rgba(212, 162, 76, 0.25);
  border-radius: 4px 0 0 0;
  pointer-events: none;
}

.mg-end-card::after {
  content: '';
  position: absolute;
  bottom: 10px; right: 10px;
  width: 22px; height: 22px;
  border-bottom: 1.5px solid rgba(212, 162, 76, 0.25);
  border-right: 1.5px solid rgba(212, 162, 76, 0.25);
  border-radius: 0 0 4px 0;
  pointer-events: none;
}

.mg-end-glow {
  position: absolute;
  top: 40%; left: 50%;
  width: 200px; height: 200px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(212, 162, 76, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

.mg-end-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--gold);
  text-shadow: 0 0 24px var(--gold-glow);
  margin-bottom: 4px;
  position: relative;
}

.mg-end-score {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1.2;
  position: relative;
}

.mg-end-detail {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
  position: relative;
}

.mg-end-best {
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 600;
  margin-top: 10px;
  position: relative;
}

.mg-end-stars {
  font-size: 1.5rem;
  letter-spacing: 8px;
  margin: 8px 0 4px;
  position: relative;
}

.mg-end-star {
  opacity: 0.15;
  display: inline-block;
}

.mg-end-star.active {
  opacity: 1;
  color: var(--gold);
  filter: drop-shadow(0 0 8px var(--gold-glow));
  animation: mgStarPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.mg-end-star.active:nth-child(2) { animation-delay: 0.1s; }
.mg-end-star.active:nth-child(3) { animation-delay: 0.2s; }

@keyframes mgStarPop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.mg-end-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  position: relative;
}

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

/* Buttons */
.mg-btn-primary {
  padding: 11px 28px;
  border: 1px solid rgba(255, 230, 160, 0.2);
  border-radius: var(--radius);
  background: linear-gradient(175deg, #e8b84a 0%, #c9952e 50%, #a67c2e 100%);
  color: #1a1000;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
  box-shadow:
    0 4px 16px rgba(212, 162, 76, 0.3),
    inset 0 1px 0 rgba(255, 230, 160, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  text-shadow: 0 1px 0 rgba(255, 230, 160, 0.3);
}

.mg-btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}

.mg-btn-primary:hover {
  box-shadow: 0 6px 24px rgba(212, 162, 76, 0.45), inset 0 1px 0 rgba(255, 230, 160, 0.5);
  transform: translateY(-2px);
}

.mg-btn-primary:active {
  transform: scale(0.96) translateY(1px);
  transition-duration: 0.08s;
}

.mg-btn-ghost {
  padding: 10px 22px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
}

.mg-btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(212, 162, 76, 0.25);
  color: var(--text-primary);
}

.mg-btn-ghost:active {
  transform: scale(0.96);
  transition-duration: 0.08s;
}

/* Red quit variant for "Retour" button */
.mg-btn-quit {
  border-color: rgba(220, 60, 60, 0.2);
  color: #e05555;
  background: rgba(220, 60, 60, 0.06);
}

.mg-btn-quit:hover {
  border-color: rgba(220, 60, 60, 0.4);
  background: rgba(220, 60, 60, 0.12);
  color: #ff6b6b;
}

/* --- Difficulty selector --- */
.mg-diff-screen {
  padding: 56px 16px 40px;
  text-align: center;
}

.mg-diff-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.mg-diff-sub {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.mg-diff-grid {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.mg-diff-btn {
  flex: 1;
  min-width: 130px;
  max-width: 190px;
  padding: 22px 16px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  text-align: center;
}

.mg-diff-btn::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2.5px;
  background: linear-gradient(90deg, transparent, var(--diff-color, var(--gold)), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.mg-diff-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 100% 80% at 50% -30%, color-mix(in srgb, var(--diff-color, var(--gold)) 8%, transparent), transparent 70%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.mg-diff-btn:hover::before { opacity: 0.8; }
.mg-diff-btn:hover::after { opacity: 1; }

.mg-diff-btn:hover {
  border-color: color-mix(in srgb, var(--diff-color, var(--gold)) 30%, transparent);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 16px color-mix(in srgb, var(--diff-color, var(--gold)) 8%, transparent);
}

.mg-diff-btn:active { transform: scale(0.96); transition-duration: 0.1s; }

.mg-diff-btn[data-diff="easy"],
.mg-diff-btn[data-diff="slow"]   { --diff-color: var(--emerald); }
.mg-diff-btn[data-diff="medium"],
.mg-diff-btn[data-diff="normal"] { --diff-color: var(--amber-warm); }
.mg-diff-btn[data-diff="hard"],
.mg-diff-btn[data-diff="fast"]   { --diff-color: var(--ruby); }

.mg-diff-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0 auto 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--diff-color, var(--gold)) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--diff-color, var(--gold)) 12%, transparent);
  color: var(--diff-color, var(--gold));
  transition: all 0.35s ease;
}

.mg-diff-ico svg { width: 18px; height: 18px; }

.mg-diff-btn:hover .mg-diff-ico {
  transform: scale(1.1);
  background: color-mix(in srgb, var(--diff-color, var(--gold)) 16%, transparent);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--diff-color, var(--gold)) 12%, transparent);
}

.mg-diff-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 4px;
}

/* ======================================================================
   FALLING NAMES
   ====================================================================== */

.mg-falling-zone {
  position: relative;
  width: 100%;
  height: 440px;
  overflow: hidden;
  border-radius: 22px;
  background:
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(212, 162, 76, 0.04) 0%, transparent 100%),
    radial-gradient(ellipse 50% 30% at 50% 0%, rgba(96, 165, 250, 0.03) 0%, transparent 100%),
    linear-gradient(180deg, rgba(10, 14, 26, 0.95) 0%, rgba(15, 19, 36, 0.92) 100%);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Danger line at bottom */
.mg-falling-zone::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 36px;
  background: linear-gradient(to top, rgba(239, 68, 68, 0.05) 0%, transparent 100%);
  border-top: 1px dashed rgba(239, 68, 68, 0.1);
  pointer-events: none;
  transition: all 0.3s ease;
}

/* Red glow + shake when a name is missed */
.mg-falling-zone.hit {
  border-color: rgba(239, 68, 68, 0.35);
  box-shadow: var(--shadow-card), 0 0 30px rgba(239, 68, 68, 0.12), inset 0 0 40px rgba(239, 68, 68, 0.04);
  animation: mgZoneShake 0.4s ease;
}

.mg-falling-zone.hit::after {
  background: linear-gradient(to top, rgba(239, 68, 68, 0.12) 0%, transparent 100%);
  border-top-color: rgba(239, 68, 68, 0.25);
}

@keyframes mgZoneShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-4px); }
  30% { transform: translateX(4px); }
  45% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-1px); }
  90% { transform: translateX(1px); }
}

.mg-falling-name {
  position: absolute;
  font-family: var(--font-arabic);
  font-size: 1.5rem;
  color: var(--gold-light);
  text-shadow: 0 0 20px var(--gold-glow);
  padding: 12px 20px;
  background: linear-gradient(145deg, rgba(15, 19, 36, 0.92) 0%, rgba(20, 25, 48, 0.88) 100%);
  border: 1.5px solid rgba(212, 162, 76, 0.18);
  border-radius: 14px;
  white-space: nowrap;
  z-index: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  transition: border-color 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(8px);
}

/* Name nearing danger zone */
.mg-falling-name.danger {
  border-color: rgba(239, 68, 68, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 12px rgba(239, 68, 68, 0.1);
  color: #ffb3b3;
}

.mg-falling-name.caught {
  animation: mgCaught 0.45s ease forwards;
}

.mg-falling-name.missed {
  animation: mgMissed 0.35s ease forwards;
}

@keyframes mgCaught {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.2); border-color: var(--emerald); box-shadow: 0 0 24px var(--emerald-glow); color: var(--emerald); }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes mgMissed {
  0% { opacity: 1; }
  30% { border-color: var(--ruby); box-shadow: 0 0 20px var(--ruby-glow); color: #ffb3b3; }
  100% { opacity: 0; transform: translateY(12px) scale(0.85); }
}

.mg-falling-input-zone {
  margin-top: 14px;
}

.mg-falling-input {
  width: 100%;
  padding: 16px 20px;
  border: 2px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(15, 19, 36, 0.9) 0%, rgba(20, 25, 48, 0.85) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  outline: none;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  caret-color: var(--gold);
}

.mg-falling-input::placeholder { color: var(--text-muted); }

.mg-falling-input:focus {
  border-color: var(--gold);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 16px rgba(212, 162, 76, 0.12);
}

.mg-falling-input.correct {
  border-color: var(--emerald);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 16px rgba(45, 212, 160, 0.15);
}

/* Score popup float animation */
.mg-score-pop {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--emerald);
  text-shadow: 0 0 8px var(--emerald-glow);
  pointer-events: none;
  z-index: 5;
  animation: mgScorePop 0.7s ease forwards;
}

@keyframes mgScorePop {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1.3); }
}

/* ======================================================================
   MEMORY
   ====================================================================== */

.mg-memory-wrap {
  position: relative;
  min-height: 300px;
}

.mg-memory-grid {
  display: grid;
  gap: 10px;
  justify-content: center;
  padding: 4px 0;
}

.mg-memory-grid[data-cols="2"] { grid-template-columns: repeat(4, 1fr); max-width: 440px; margin: 0 auto; }
.mg-memory-grid[data-cols="3"] { grid-template-columns: repeat(4, 1fr); max-width: 520px; margin: 0 auto; }
.mg-memory-grid[data-cols="4"] { grid-template-columns: repeat(4, 1fr); max-width: 560px; margin: 0 auto; }

.mg-memory-card {
  aspect-ratio: 3 / 4;
  perspective: 1200px;
  cursor: pointer;
}

.mg-memory-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

.mg-memory-card.flipped .mg-memory-card-inner {
  transform: rotateY(180deg);
}

.mg-memory-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 10px 8px;
  text-align: center;
  overflow: hidden;
}

.mg-memory-card-back {
  background: linear-gradient(145deg, rgba(15, 19, 36, 0.95) 0%, rgba(22, 28, 52, 0.9) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
}

.mg-memory-card-back::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(212, 162, 76, 0.06) 0%, transparent 55%);
  pointer-events: none;
}

.mg-memory-card-back::after {
  content: '\2726';
  font-size: 1.6rem;
  color: var(--gold);
  opacity: 0.25;
  text-shadow: 0 0 10px var(--gold-glow);
}

.mg-memory-card-front {
  background: linear-gradient(160deg, rgba(12, 15, 30, 0.98) 0%, rgba(20, 26, 52, 0.95) 100%);
  border: 1.5px solid rgba(212, 162, 76, 0.12);
  border-radius: 14px;
  transform: rotateY(180deg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.mg-memory-card-front::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(212, 162, 76, 0.04) 0%, transparent 65%);
  pointer-events: none;
}

.mg-memory-card-front.arabic {
  font-family: var(--font-arabic);
  font-size: 1.25rem;
  color: var(--gold-light);
  line-height: 1.3;
  text-shadow: 0 0 12px rgba(212, 162, 76, 0.2);
}

.mg-memory-card-front.french {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.3;
}

.mg-memory-card.matched .mg-memory-card-inner { transform: rotateY(180deg); }

.mg-memory-card.matched .mg-memory-card-front {
  border-color: rgba(45, 212, 160, 0.3);
  box-shadow: 0 0 20px var(--emerald-glow), 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: mgMemoryPulse 0.5s ease;
}

.mg-memory-card.no-match .mg-memory-card-front {
  border-color: rgba(239, 68, 68, 0.3);
  box-shadow: 0 0 12px var(--ruby-glow);
  animation: mgMemoryShake 0.4s ease;
}

@keyframes mgMemoryPulse {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.06); }
}

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

/* ======================================================================
   WORD SEARCH
   ====================================================================== */

.mg-ws-wrap {
  position: relative;
  min-height: 300px;
}

.mg-ws-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mg-ws-grid-wrap {
  background:
    radial-gradient(ellipse 60% 50% at 50% 50%, rgba(212, 162, 76, 0.03) 0%, transparent 100%),
    linear-gradient(160deg, rgba(12, 15, 30, 0.95) 0%, rgba(20, 26, 52, 0.9) 100%);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 22px;
  padding: 16px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  position: relative;
  overflow: hidden;
}

.mg-ws-grid-wrap::before {
  content: '';
  position: absolute;
  top: 8px; left: 8px;
  width: 20px; height: 20px;
  border-top: 1.5px solid rgba(212, 162, 76, 0.15);
  border-left: 1.5px solid rgba(212, 162, 76, 0.15);
  border-radius: 3px 0 0 0;
  pointer-events: none;
  z-index: 2;
}

.mg-ws-grid-wrap::after {
  content: '';
  position: absolute;
  bottom: 8px; right: 8px;
  width: 20px; height: 20px;
  border-bottom: 1.5px solid rgba(212, 162, 76, 0.15);
  border-right: 1.5px solid rgba(212, 162, 76, 0.15);
  border-radius: 0 0 3px 0;
  pointer-events: none;
  z-index: 2;
}

.mg-ws-grid { display: grid; gap: 2px; }
.mg-ws-grid[data-size="10"] { grid-template-columns: repeat(10, 1fr); }
.mg-ws-grid[data-size="12"] { grid-template-columns: repeat(12, 1fr); }

.mg-ws-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.mg-ws-cell:hover {
  background: rgba(212, 162, 76, 0.08);
  color: var(--text-primary);
}

.mg-ws-cell.selecting {
  background: rgba(212, 162, 76, 0.2);
  color: var(--gold-light);
  box-shadow: inset 0 0 6px rgba(212, 162, 76, 0.1);
}

.mg-ws-cell.found {
  background: rgba(212, 162, 76, 0.15);
  color: var(--gold);
  font-weight: 700;
  text-shadow: 0 0 8px var(--gold-glow);
}

.mg-ws-cell.wrong {
  animation: mgWSShake 0.3s ease;
  background: rgba(239, 68, 68, 0.1);
  color: var(--ruby);
}

@keyframes mgWSShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.mg-ws-clues {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 0 4px;
}

.mg-ws-clue {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: linear-gradient(135deg, rgba(15, 19, 36, 0.7) 0%, rgba(10, 14, 28, 0.8) 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  color: var(--text-secondary);
  transition: all 0.3s ease;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}

.mg-ws-clue-word {
  font-weight: 700;
  color: var(--text-primary);
}

.mg-ws-clue.found {
  background: rgba(212, 162, 76, 0.08);
  border-color: rgba(212, 162, 76, 0.2);
  color: var(--gold);
  opacity: 0.7;
}

.mg-ws-clue.found .mg-ws-clue-word {
  text-decoration: line-through;
  color: var(--gold);
}

/* ======================================================================
   RESPONSIVE
   ====================================================================== */

/* Tablet */
@media (max-width: 700px) {
  .mg-hub {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px 0 32px;
  }

  .mg-hub-card {
    flex-direction: row;
    align-items: stretch;
    text-align: left;
  }

  .mg-hub-banner {
    width: auto;
    min-width: 80px;
    padding: 18px 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  }

  .mg-hub-banner::before {
    /* Shimmer on left edge instead of top */
    top: 0; left: 0; bottom: 0; right: auto;
    width: 2px; height: 100%;
    background: linear-gradient(180deg, transparent, var(--mg-color), transparent);
  }

  .mg-hub-ico {
    width: 46px;
    height: 46px;
    border-radius: 14px;
  }

  .mg-hub-ico svg { width: 22px; height: 22px; }

  .mg-hub-body {
    align-items: flex-start;
    padding: 14px 16px;
    gap: 4px;
  }

  .mg-hub-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .mg-hub-play {
    margin-top: auto;
    padding: 5px 16px;
    font-size: 0.72rem;
  }

  .mg-hub-play svg { width: 12px; height: 12px; }
}

/* Mobile */
@media (max-width: 600px) {
  .mg-topbar-hero { padding: 16px 14px 0; }
  .mg-topbar-hero-body { padding: 18px 0 24px; }
  .mg-topbar-hero-icon { width: 48px; height: 48px; }
  .mg-topbar-hero-icon svg { width: 22px; height: 22px; }
  .mg-topbar-hero-title { font-size: 0.95rem; }

  .mg-hub { gap: 8px; padding: 12px 0 24px; }

  .mg-hub-banner { min-width: 68px; padding: 14px 12px; }
  .mg-hub-ico { width: 40px; height: 40px; border-radius: 12px; }
  .mg-hub-ico svg { width: 20px; height: 20px; }

  .mg-hub-body { padding: 10px 12px; }
  .mg-hub-title { font-size: 0.92rem; }
  .mg-hub-desc { font-size: 0.72rem; }
  .mg-hub-best { font-size: 0.68rem; }

  /* Game header */
  .mg-game-header {
    padding: 10px 12px;
    gap: 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
  }
  .mg-stat { font-size: 0.82rem; gap: 4px; }
  .mg-stat-label { font-size: 0.72rem; }
  .mg-level-badge { padding: 3px 10px; font-size: 0.72rem; }
  .mg-heart { width: 16px; height: 16px; }

  /* Falling Names */
  .mg-falling-zone {
    height: calc(100dvh - 260px);
    min-height: 260px;
    border-radius: var(--radius);
  }
  .mg-falling-name { font-size: 1.2rem; padding: 8px 14px; border-radius: var(--radius-sm); }
  .mg-falling-input {
    padding: 12px 14px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
  }
  .mg-falling-input-zone { margin-top: 10px; }

  /* Memory */
  .mg-memory-grid { gap: 6px; }
  .mg-memory-card-front.arabic { font-size: 1rem; }
  .mg-memory-card-front.french { font-size: 0.65rem; }
  .mg-memory-card-back::after { font-size: 1.2rem; }

  /* Word Search */
  .mg-ws-grid-wrap { padding: 8px; border-radius: var(--radius); }
  .mg-ws-grid { gap: 1px; }
  .mg-ws-cell { font-size: 0.68rem; border-radius: 3px; }
  .mg-ws-clues { gap: 4px; padding: 0; }
  .mg-ws-clue { padding: 5px 10px; font-size: 0.7rem; }

  /* Difficulty selector */
  .mg-diff-screen { padding: 32px 0 24px; }
  .mg-diff-title { font-size: 1.2rem; }
  .mg-diff-sub { font-size: 0.8rem; margin-bottom: 20px; }
  .mg-diff-grid { gap: 8px; }
  .mg-diff-btn {
    min-width: 0;
    max-width: none;
    padding: 16px 12px;
    font-size: 0.88rem;
    border-radius: var(--radius);
  }
  .mg-diff-ico { width: 32px; height: 32px; border-radius: 9px; margin-bottom: 6px; }
  .mg-diff-ico svg { width: 16px; height: 16px; }
  .mg-diff-label { font-size: 0.66rem; margin-top: 3px; }

  /* End screen */
  .mg-end-overlay { padding: 12px; }
  .mg-end-card { padding: 22px 16px; border-radius: var(--radius); }
  .mg-end-title { font-size: 1.2rem; }
  .mg-end-score { font-size: 2rem; }
  .mg-end-detail { font-size: 0.8rem; }
  .mg-end-best { font-size: 0.75rem; }
  .mg-end-stars { font-size: 1.3rem; letter-spacing: 6px; }
  .mg-end-actions { gap: 8px; margin-top: 14px; }
  .mg-btn-primary { padding: 10px 22px; font-size: 0.84rem; }
  .mg-btn-ghost { padding: 9px 18px; font-size: 0.78rem; }
}

/* Very small screens */
@media (max-width: 380px) {
  .mg-hub-banner { min-width: 58px; padding: 12px 10px; }
  .mg-hub-ico { width: 36px; height: 36px; }
  .mg-hub-body { padding: 8px 10px; }
  .mg-hub-title { font-size: 0.85rem; }
  .mg-hub-play { display: none; }

  .mg-falling-zone { height: calc(100dvh - 240px); min-height: 220px; }

  .mg-diff-grid { flex-direction: column; align-items: center; }
  .mg-diff-btn { width: 100%; max-width: 240px; }

  .mg-memory-grid { gap: 4px; }
  .mg-memory-card-front.arabic { font-size: 0.88rem; }
  .mg-memory-card-front.french { font-size: 0.6rem; }
}

/* ======================================================================
   TOP CONTROLS — Back + Sound toggle
   ====================================================================== */

.mg-top-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

/* Red quit button for mini-games */
.mg-quit-btn {
  border-color: rgba(220, 60, 60, 0.25);
  background: rgba(220, 60, 60, 0.08);
  color: #e05555;
}

.mg-quit-btn:hover {
  border-color: rgba(220, 60, 60, 0.5);
  background: rgba(220, 60, 60, 0.15);
  color: #ff6b6b;
  box-shadow: 0 0 16px rgba(220, 60, 60, 0.15);
}

/* Sound toggle button */
.mg-sound-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--gold);
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
  flex-shrink: 0;
  overflow: hidden;
}

.mg-sound-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(212, 162, 76, 0.25);
}

.mg-sound-toggle:active {
  transform: scale(0.92);
  transition: transform 0.1s ease;
}

/* Icon layers */
.mg-sound-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mg-sound-icon svg {
  width: 20px;
  height: 20px;
}

/* Sound ON icon — visible by default */
.mg-sound-on {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Sound OFF icon — hidden by default */
.mg-sound-off {
  opacity: 0;
  transform: scale(0.3) rotate(-90deg);
}

/* MUTED state — swap icons */
.mg-sound-toggle.muted {
  color: var(--text-secondary);
  border-color: rgba(255, 255, 255, 0.04);
  background: rgba(255, 255, 255, 0.02);
}

.mg-sound-toggle.muted .mg-sound-on {
  opacity: 0;
  transform: scale(0.3) rotate(90deg);
}

.mg-sound-toggle.muted .mg-sound-off {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}
