/* Memory Pairs. Logical properties only, so RTL and LTR share one file.
   Keyframes carry the mc- prefix so they never clash with shared styles. */
:root {
    --bg: #0f1226; --surface: #181c38; --border: #2a2f57; --text: #eef0ff; --muted: #a3a8d1;
    --accent: #ffb020; --gold: #ffd34d; --ink: #1a1300; --ok: #4ade80; --bad: #ff6b6b;
    --blue: #2a52d6; --blue-d: #142a7c;
    --gap: clamp(6px, 1.6vw, 10px);
    --font: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Sans", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; color: var(--text); font-family: var(--font); }
html { background: var(--bg); }
body {
    background: radial-gradient(120% 70% at 50% 0%, #1d2458 0%, rgba(29, 36, 88, 0) 70%), var(--bg);
    -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; }

.game { max-inline-size: 720px; margin-inline: auto; padding: 8px; }

.hud { display: flex; align-items: center; gap: 8px; margin-block-end: 6px; }
.stat {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding-block: 4px;
}
.stat .k { font-size: .72rem; color: var(--muted); }
.stat b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat.bump b { animation: mc-bump .35s ease-out; color: var(--ok); }
.icon {
    flex: none; inline-size: 44px; block-size: 44px; border-radius: 12px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center;
}
.icon svg { inline-size: 22px; block-size: 22px; }
.icon:focus-visible, .card:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Pairs found, as a thin bar that fills with the board. */
.meter { block-size: 5px; border-radius: 99px; background: var(--surface); overflow: hidden; margin-block-end: 10px; }
.meter i {
    display: block; block-size: 100%; transform: scaleX(0); transform-origin: left;
    background: linear-gradient(90deg, var(--accent), var(--gold), var(--ok)); transition: transform .45s cubic-bezier(.3, 1.3, .5, 1);
}
[dir="rtl"] .meter i { transform-origin: right; }

.board-wrap { position: relative; }
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
@media (min-width: 560px) { .board { grid-template-columns: repeat(6, 1fr); } }
.board.nudge { animation: mc-nudge .3s ease-out; }

.card {
    position: relative; aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer;
    perspective: 700px; touch-action: manipulation;
}
.card .in {
    position: absolute; inset: 0; transform-style: preserve-3d;
    transition: transform .36s cubic-bezier(.3, 1.4, .5, 1), translate .18s ease-out;
}
.card.up .in { transform: rotateY(180deg); }
.card.deal .in { transition: none; animation: mc-deal .45s cubic-bezier(.3, 1.4, .5, 1) backwards; animation-delay: calc(var(--n) * 18ms); }
@media (hover: hover) { .card:not(.up):hover .in { translate: 0 -3px; } }
.face, .back {
    position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
    display: grid; place-items: center; overflow: hidden;
}
/* Card back: stadium blue with a gold medal in the middle. */
.back {
    background:
        radial-gradient(circle at 50% 50%, var(--gold) 0 9%, #c98a00 10% 12%, transparent 13%),
        radial-gradient(circle at 50% 50%, transparent 0 20%, rgba(255, 211, 77, .55) 21% 23%, transparent 24%),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .06) 0 5px, transparent 5px 11px),
        linear-gradient(150deg, var(--blue), var(--blue-d));
    border: 1px solid #3f67e8; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 3px 0 #0a0c1c;
}
.card:hover .back { border-color: var(--gold); }
.board.hint .card .back { animation: mc-breathe 1.6s ease-in-out infinite; animation-delay: calc(var(--n) * 60ms); }
.face {
    transform: rotateY(180deg); background: linear-gradient(160deg, #ffffff, #ece9fb); box-shadow: 0 3px 0 #b9b5d6;
}
.face svg { inline-size: 62%; block-size: 62%; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .18)); }
/* A shine sweeps over a matched pair. */
.face::after {
    content: ""; position: absolute; inset: -20%; opacity: 0; pointer-events: none;
    background: linear-gradient(110deg, transparent 35%, rgba(255, 255, 255, .85) 50%, transparent 65%);
}
.card.done .face { animation: mc-pop .42s ease-out; box-shadow: 0 0 0 3px var(--c, var(--ok)), 0 0 18px var(--c, var(--ok)); }
.card.done .face::after { animation: mc-shine .7s ease-out .1s; }
.card.done { cursor: default; }
.card.miss .face { animation: mc-shake .38s ease-in-out; box-shadow: 0 0 0 3px var(--bad); }
.board.cheer .card.done .face { animation: mc-hop .45s ease-out backwards; animation-delay: calc(var(--n) * 20ms); }

@keyframes mc-pop { 0% { scale: 1; } 45% { scale: 1.14; } 100% { scale: 1; } }
@keyframes mc-hop { 0%, 100% { translate: 0 0; } 40% { translate: 0 -10%; } }
@keyframes mc-shake { 0%, 100% { translate: 0; } 25% { translate: -5px; } 75% { translate: 5px; } }
@keyframes mc-nudge { 30% { translate: 3px 0; } 60% { translate: -2px 0; } }
@keyframes mc-deal { from { opacity: 0; scale: .55; translate: 0 18px; } }
@keyframes mc-breathe { 0%, 100% { filter: none; } 50% { filter: brightness(1.25); } }
@keyframes mc-shine { from { opacity: 1; translate: -70% 0; } to { opacity: 1; translate: 70% 0; } }
@keyframes mc-bump { 40% { scale: 1.25; } }

/* Effects layer: sparks, rings and word popups over the board. */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.fx .spark {
    position: absolute; inline-size: 7px; block-size: 7px; margin: -3.5px; border-radius: 50%; background: var(--c);
    animation: mc-spark .7s cubic-bezier(.2, .7, .4, 1) forwards;
}
.fx .ring {
    position: absolute; inline-size: var(--s); block-size: var(--s); margin: calc(var(--s) / -2);
    border: 3px solid var(--c); border-radius: 18px; animation: mc-ring .55s ease-out forwards;
}
.fx .pop {
    position: absolute; translate: -50% -50%; white-space: nowrap; font-weight: 900; font-size: clamp(1rem, 4.2vw, 1.35rem);
    color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .45), 0 0 14px rgba(0, 0, 0, .35);
    background: rgba(15, 18, 38, .72); border: 1px solid rgba(255, 255, 255, .15); padding: 3px 12px; border-radius: 99px;
    animation: mc-float 1.05s ease-out forwards;
}
.fx .pop.hot { color: var(--gold); border-color: rgba(255, 211, 77, .5); }
.fx .pop.lucky { color: #7dd3fc; }
.fx .pop.sharp { color: var(--ok); }
@keyframes mc-spark { from { transform: translate(0, 0) scale(var(--z)); } to { transform: translate(var(--dx), var(--dy)) scale(0); } }
@keyframes mc-ring { from { transform: scale(.85); opacity: .9; } to { transform: scale(1.35); opacity: 0; } }
@keyframes mc-float {
    0% { opacity: 0; transform: translateY(8px) scale(.6); }
    18% { opacity: 1; transform: translateY(0) scale(1.08); }
    30% { transform: translateY(0) scale(1); }
    75% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-26px) scale(1); }
}

.overlay {
    position: absolute; inset: 0; display: none; align-content: start; justify-content: center; justify-items: center; gap: 12px;
    text-align: center; padding: clamp(20px, 9%, 72px) 16px 16px; border-radius: 16px; z-index: 3;
    background: rgba(15, 18, 38, .86); backdrop-filter: blur(3px);
}
@media (pointer: coarse) { .overlay { backdrop-filter: none; background: rgba(15, 18, 38, .93); } }
.overlay.show { display: grid; animation: mc-fade .25s ease-out; }
.overlay h2 { margin: 0; font-size: clamp(1.3rem, 5vw, 1.8rem); }
.overlay p { margin: 0; color: var(--muted); max-inline-size: 34ch; }
.overlay .small { font-size: .85rem; }
.overlay .logo { display: flex; gap: 8px; }
.overlay .logo svg {
    inline-size: 46px; block-size: 46px; padding: 8px; border-radius: 12px; background: #f6f4ff; box-shadow: 0 3px 0 #b9b5d6;
    animation: mc-wobble 2.4s ease-in-out infinite;
}
.overlay .logo svg + svg { animation-delay: -1.2s; }
@keyframes mc-wobble { 0%, 100% { rotate: -6deg; } 50% { rotate: 6deg; translate: 0 -3px; } }
.overlay .end { display: grid; justify-items: center; gap: 10px; inline-size: 100%; }
.overlay .big { font-size: clamp(2.4rem, 11vw, 3.6rem); font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.overlay .big.bump { animation: mc-bump .35s ease-out; }
.overlay .big.glow { color: var(--gold); text-shadow: 0 0 22px rgba(255, 211, 77, .6); }
.overlay .rec {
    font-weight: 900; color: var(--ink); background: linear-gradient(90deg, var(--gold), var(--accent));
    padding: 4px 14px; border-radius: 99px; animation: mc-stamp .5s cubic-bezier(.3, 1.6, .5, 1);
}
.overlay .rec[hidden] { display: none; }
@keyframes mc-stamp { from { opacity: 0; scale: 2; rotate: -8deg; } }
.overlay .stats { display: grid; grid-template-columns: repeat(4, auto); gap: 6px 18px; color: var(--muted); font-size: .85rem; }
.overlay .stats div { display: grid; justify-items: center; }
.overlay .stats b { color: var(--text); font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.overlay .stats b.bump { animation: mc-bump .3s ease-out; }
@media (max-width: 380px) { .overlay .stats { grid-template-columns: repeat(2, auto); } }
.overlay .note { color: var(--text); font-weight: 600; }
.overlay .note.ok { color: var(--ok); }
.overlay .note.bad { color: var(--bad); }
#note { display: grid; gap: 6px; justify-items: center; }
.stars { font-size: 2.2rem; letter-spacing: 4px; color: #4a4f80; line-height: 1; }
.stars span { display: inline-block; transition: color .2s; }
.stars .on { color: var(--accent); animation: mc-star .45s cubic-bezier(.3, 1.6, .5, 1); text-shadow: 0 0 14px rgba(255, 176, 32, .55); }
@keyframes mc-star { from { scale: .2; rotate: -40deg; } 60% { scale: 1.35; } }
@keyframes mc-fade { from { opacity: 0; } }

.btn {
    border: 0; cursor: pointer; background: var(--accent); color: var(--ink); font-weight: 800; font-size: 1.1rem;
    padding-block: 12px; padding-inline: 34px; border-radius: 999px; box-shadow: 0 4px 0 #b97700;
}
.btn:active { translate: 0 2px; box-shadow: 0 2px 0 #b97700; }
.btn.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 2px var(--border); font-size: .95rem; padding-block: 8px; }

.mode { margin-block: 10px 0; text-align: center; color: var(--muted); font-size: .85rem; min-block-size: 1.3em; }
.mode.tip { color: var(--gold); font-weight: 700; animation: mc-fade .3s ease-out; }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 4; }
.confetti i {
    position: absolute; inset-block-start: -10px; inline-size: 8px; block-size: 12px; border-radius: 2px;
    animation: mc-fall var(--d) ease-in forwards; animation-delay: var(--w);
}
@keyframes mc-fall { to { transform: translate(var(--x), 110vh) rotate(var(--r)); } }

@media (prefers-reduced-motion: reduce) {
    .card .in { transition: none; }
    .card.done .face, .card.miss .face, .card.done .face::after, .card.deal .in, .board.cheer .card.done .face,
    .board.nudge, .board.hint .card .back, .overlay.show, .overlay .logo svg, .stars .on, .overlay .rec, .mode.tip { animation: none; }
    .confetti, .fx { display: none; }
}
