/* ==========================================================
   Match Mind — game UI (shared by aura-join.html + index.html)
   Prefix: .mmg-  (kept separate from legacy .mm-* so the
   theme-override.css radius rules don't touch it)
   ========================================================== */

.mmg {
    --mmg-bg-1: #0b1024;
    --mmg-bg-2: #151b3d;
    --mmg-surface: rgba(255, 255, 255, 0.06);
    --mmg-line: rgba(255, 255, 255, 0.10);
    --mmg-text: #f1f5ff;
    --mmg-muted: rgba(226, 232, 255, 0.62);
    --mmg-accent: #7c6cff;
    --mmg-accent-2: #22d3ee;
    --mmg-good: #22c55e;
    --mmg-bad: #f43f5e;
    --mmg-warn: #f59e0b;
    --mmg-card: #ffffff;
    --mmg-card-text: #0f172a;
    --mmg-card-muted: #64748b;
    --mmg-radius: 18px;
    --mmg-gap: 12px;

    position: relative;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-family: 'Outfit', system-ui, sans-serif;
    color: var(--mmg-text);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.mmg *, .mmg *::before, .mmg *::after { box-sizing: border-box; }
/* Site themes restyle h1–h6 (serif, navy) — keep the game's own type */
.mmg h2, .mmg h3 { font-family: 'Outfit', system-ui, sans-serif !important; letter-spacing: -0.01em; }

/* Full-screen host used by the in-lesson overlay */
.mmg-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    background:
        radial-gradient(1200px 600px at 85% -10%, rgba(124, 108, 255, 0.28), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, 0.18), transparent 60%),
        linear-gradient(160deg, #0b1024, #121838 60%, #0b1024);
    animation: mmgFade .35s ease;
}

/* aura-join host: trim the generic page padding while the game runs */
.game-content.mmg-host { padding: 16px 14px 40px !important; }

/* ---------- HUD ---------- */
.mmg-hud {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(124, 108, 255, 0.16), rgba(34, 211, 238, 0.08));
    border: 1px solid var(--mmg-line);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.mmg-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.mmg-logo {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 1.2rem;
    color: #fff;
    background: linear-gradient(135deg, var(--mmg-accent), #a855f7);
    box-shadow: 0 8px 24px rgba(124, 108, 255, 0.45);
}

.mmg-title h2 {
    margin: 0;
    font-size: clamp(1rem, 2.4vw, 1.3rem);
    font-weight: 800;
    line-height: 1.2;
    color: var(--mmg-text) !important;
    -webkit-text-fill-color: var(--mmg-text) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mmg-title small {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--mmg-muted);
    letter-spacing: .02em;
}

.mmg-tools { display: flex; align-items: center; gap: 8px; }

.mmg-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: 1px solid var(--mmg-line);
    background: var(--mmg-surface);
    color: var(--mmg-text);
    font-size: 1rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .2s, transform .15s;
}
.mmg-icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.mmg-icon-btn:active { transform: scale(.94); }

.mmg-stats {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.mmg-stat {
    position: relative;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(8, 12, 32, 0.45);
    border: 1px solid var(--mmg-line);
    min-width: 0;
}

.mmg-stat label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--mmg-muted);
}

.mmg-stat b {
    display: block;
    margin-top: 2px;
    font-size: clamp(1.05rem, 2.6vw, 1.45rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--mmg-text);
    -webkit-text-fill-color: var(--mmg-text);
}

.mmg-stat.is-bump b { animation: mmgBump .35s ease; }

.mmg-stat-timer.is-warn { border-color: rgba(245, 158, 11, 0.55); }
.mmg-stat-timer.is-warn b { color: var(--mmg-warn); -webkit-text-fill-color: var(--mmg-warn); }
.mmg-stat-timer.is-danger { border-color: rgba(244, 63, 94, 0.6); animation: mmgPulse 1s ease infinite; }
.mmg-stat-timer.is-danger b { color: var(--mmg-bad); -webkit-text-fill-color: var(--mmg-bad); }

.mmg-progress {
    grid-column: 1 / -1;
    height: 8px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}
.mmg-progress > i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--mmg-accent), var(--mmg-accent-2));
    box-shadow: 0 0 16px rgba(34, 211, 238, 0.6);
    transition: width .5s cubic-bezier(.22, 1, .36, 1);
}

/* ---------- Hint / toast line ---------- */
.mmg-hint {
    min-height: 26px;
    text-align: center;
    font-size: .92rem;
    font-weight: 600;
    color: var(--mmg-muted);
    transition: color .2s;
}
.mmg-hint.is-good { color: #4ade80; }
.mmg-hint.is-bad { color: #fb7185; }
.mmg-hint.is-combo { color: #fbbf24; }

/* ---------- Board ---------- */
.mmg-stage { display: flex; flex-direction: column; position: relative; }

.mmg-board {
    display: grid;
    grid-template-columns: repeat(var(--mmg-cols, 4), minmax(0, 1fr));
    gap: var(--mmg-gap);
    touch-action: manipulation;
}

.mmg-card {
    --pair: var(--mmg-accent);
    position: relative;
    min-height: var(--mmg-card-h, 118px);
    padding: 14px 12px;
    border: 0;
    border-radius: var(--mmg-radius);
    background: var(--mmg-card);
    color: var(--mmg-card-text);
    font: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.9) inset,
        0 -3px 0 rgba(15, 23, 42, 0.08) inset,
        0 10px 24px rgba(2, 6, 23, 0.35);
    transition:
        transform .22s cubic-bezier(.34, 1.56, .64, 1),
        box-shadow .22s ease,
        background .22s ease,
        opacity .3s ease;
    animation: mmgDeal .45s cubic-bezier(.22, 1, .36, 1) backwards;
    animation-delay: calc(var(--i, 0) * 35ms);
    touch-action: none;
    outline: none;
    overflow: hidden;
}

.mmg-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid transparent;
    pointer-events: none;
    transition: border-color .2s;
}

@media (hover: hover) {
    .mmg-card:not(.is-matched):hover { transform: translateY(-3px); }
}

.mmg-card:focus-visible::before { border-color: var(--mmg-accent-2); }

.mmg-card:active:not(.is-matched) { transform: scale(.97); }

.mmg-card-img {
    width: 100%;
    max-height: calc(var(--mmg-card-h, 118px) * 0.52);
    object-fit: contain;
    border-radius: 10px;
    pointer-events: none;
    -webkit-user-drag: none;
}

.mmg-card-text {
    font-weight: 700;
    line-height: 1.25;
    font-size: var(--fs, 1.05rem);
    color: var(--mmg-card-text);
    -webkit-text-fill-color: var(--mmg-card-text);
    overflow-wrap: break-word;
    hyphens: auto;
    pointer-events: none;
}

.mmg-card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: .75rem;
    color: #fff;
    background: var(--pair);
    transform: scale(0);
    transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
    pointer-events: none;
}
[dir="rtl"] .mmg-card-badge, .mmg[dir="rtl"] .mmg-card-badge { right: auto; left: 8px; }

/* selected */
.mmg-card.is-selected {
    transform: translateY(-6px) scale(1.03);
    background: #f5f3ff;
    box-shadow:
        0 0 0 3px var(--mmg-accent),
        0 0 0 8px rgba(124, 108, 255, 0.25),
        0 18px 36px rgba(76, 60, 220, 0.45);
}

/* drop target while dragging */
.mmg-card.is-target {
    transform: scale(1.05);
    box-shadow:
        0 0 0 3px var(--mmg-accent-2),
        0 0 0 9px rgba(34, 211, 238, 0.25),
        0 18px 36px rgba(8, 145, 178, 0.45);
}

/* being dragged (source stays as a placeholder) */
.mmg-card.is-lifted { opacity: .35; transform: scale(.96); }

/* matched */
.mmg-card.is-matched {
    cursor: default;
    background: linear-gradient(160deg, color-mix(in srgb, var(--pair) 20%, #ffffff), color-mix(in srgb, var(--pair) 8%, #ffffff));
    box-shadow:
        0 0 0 3px var(--pair),
        0 10px 22px color-mix(in srgb, var(--pair) 35%, transparent);
    animation: mmgMatch .55s cubic-bezier(.34, 1.56, .64, 1);
}
.mmg-card.is-matched .mmg-card-text {
    color: color-mix(in srgb, var(--pair) 55%, #0f172a);
    -webkit-text-fill-color: color-mix(in srgb, var(--pair) 55%, #0f172a);
}
.mmg-card.is-matched .mmg-card-badge { transform: scale(1); }
.mmg-card.is-settled { transform: scale(.96); box-shadow: 0 0 0 2px var(--pair), 0 4px 10px rgba(2, 6, 23, 0.25); }

/* wrong */
.mmg-card.is-wrong {
    background: #fff1f2;
    box-shadow:
        0 0 0 3px var(--mmg-bad),
        0 12px 26px rgba(225, 29, 72, 0.35);
    animation: mmgShake .42s ease;
}

/* ghost that follows the finger */
.mmg-ghost {
    position: fixed;
    z-index: 1000001;
    pointer-events: none;
    transform: translate(-50%, -50%) rotate(-3deg) scale(1.06);
    box-shadow: 0 24px 48px rgba(2, 6, 23, 0.55), 0 0 0 3px var(--mmg-accent);
    animation: none !important;
    opacity: .96;
}

/* score pop */
.mmg-pop {
    position: fixed;
    z-index: 1000002;
    pointer-events: none;
    font-weight: 900;
    font-size: 1.25rem;
    color: #fbbf24;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    transform: translate(-50%, -50%);
    animation: mmgRise .9s ease forwards;
}
.mmg-pop.is-bad { color: #fb7185; font-size: 1rem; }

/* ---------- Start / result panels ---------- */
.mmg-panel {
    align-self: center;
    width: min(520px, 100%);
    margin-top: 6px;
    padding: 28px 24px;
    border-radius: 28px;
    text-align: center;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.04));
    border: 1px solid var(--mmg-line);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    animation: mmgPanel .5s cubic-bezier(.22, 1, .36, 1);
}

.mmg-panel h3 {
    margin: 10px 0 6px;
    font-size: clamp(1.4rem, 4vw, 1.9rem);
    font-weight: 900;
    color: var(--mmg-text) !important;
    -webkit-text-fill-color: var(--mmg-text) !important;
}

.mmg-panel p {
    margin: 0 0 18px;
    color: var(--mmg-muted);
    font-weight: 500;
}

.mmg-hero {
    width: 84px;
    height: 84px;
    margin: 0 auto;
    border-radius: 26px;
    display: grid;
    place-items: center;
    font-size: 2.2rem;
    color: #fff;
    background: linear-gradient(135deg, var(--mmg-accent), #a855f7);
    box-shadow: 0 16px 40px rgba(124, 108, 255, 0.5);
}
.mmg-hero.is-good { background: linear-gradient(135deg, #22c55e, #10b981); box-shadow: 0 16px 40px rgba(34, 197, 94, 0.45); }
.mmg-hero.is-warn { background: linear-gradient(135deg, #f59e0b, #f97316); box-shadow: 0 16px 40px rgba(245, 158, 11, 0.45); }

.mmg-howto {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
    text-align: start;
}
.mmg-howto div {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(8, 12, 32, 0.45);
    border: 1px solid var(--mmg-line);
    font-size: .88rem;
    font-weight: 600;
    color: var(--mmg-text);
}
.mmg-howto i { color: var(--mmg-accent-2); font-size: 1.1rem; width: 20px; text-align: center; }

.mmg-stars { display: flex; justify-content: center; gap: 8px; margin: 14px 0 6px; }
.mmg-stars i {
    font-size: 2.1rem;
    color: rgba(255, 255, 255, 0.15);
    transform: scale(0);
    animation: mmgStar .5s cubic-bezier(.34, 1.56, .64, 1) forwards;
}
.mmg-stars i.on { color: #fbbf24; filter: drop-shadow(0 4px 12px rgba(251, 191, 36, 0.55)); }
.mmg-stars i:nth-child(2) { animation-delay: .15s; }
.mmg-stars i:nth-child(3) { animation-delay: .3s; }

.mmg-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 16px 0 4px;
}
.mmg-summary div {
    padding: 12px;
    border-radius: 16px;
    background: rgba(8, 12, 32, 0.45);
    border: 1px solid var(--mmg-line);
}
.mmg-summary b {
    display: block;
    font-size: 1.4rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: var(--mmg-text);
    -webkit-text-fill-color: var(--mmg-text);
}
.mmg-summary span {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--mmg-muted);
}

.mmg-btn {
    min-height: 54px;
    padding: 0 30px;
    border: 0;
    border-radius: 16px;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, var(--mmg-accent), #a855f7);
    box-shadow: 0 12px 30px rgba(124, 108, 255, 0.45);
    transition: transform .15s, box-shadow .2s;
}
.mmg-btn:hover { box-shadow: 0 16px 36px rgba(124, 108, 255, 0.6); }
.mmg-btn:active { transform: scale(.97); }

/* ---------- Rush penalty (guessing too fast) ---------- */
.mmg-penalty {
    position: absolute;
    inset: -6px;
    z-index: 5;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: min(12vh, 90px);
    border-radius: 22px;
    background: rgba(8, 12, 32, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: mmgFade .25s ease;
}
.mmg-penalty-card {
    width: min(380px, calc(100% - 24px));
    padding: 24px 20px;
    border-radius: 24px;
    text-align: center;
    background: linear-gradient(160deg, #1f1533, #2a1430);
    border: 1px solid rgba(244, 63, 94, 0.45);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(244, 63, 94, 0.12);
    animation: mmgPanel .4s cubic-bezier(.22, 1, .36, 1);
}
.mmg-penalty-icon {
    width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 20px;
    display: grid; place-items: center; font-size: 1.7rem; color: #fff;
    background: linear-gradient(135deg, #f43f5e, #f97316);
    box-shadow: 0 12px 30px rgba(244, 63, 94, 0.45);
}
.mmg-penalty-card h3 {
    margin: 6px 0 4px;
    font-family: 'Outfit', system-ui, sans-serif !important;
    font-size: 1.5rem; font-weight: 900;
    color: #fff !important; -webkit-text-fill-color: #fff !important;
}
.mmg-penalty-card p { margin: 0 0 14px; color: rgba(255, 228, 230, 0.85); font-weight: 600; font-size: .95rem; }
.mmg-penalty-count b {
    display: block; font-size: 3.2rem; line-height: 1; font-weight: 900;
    font-variant-numeric: tabular-nums; color: #fb7185; -webkit-text-fill-color: #fb7185;
}
.mmg-penalty-count span { font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: rgba(255, 228, 230, 0.7); }
.mmg-penalty-card small { display: block; margin-top: 12px; color: rgba(255, 228, 230, 0.7); font-weight: 600; }
.mmg-rush-note {
    margin-top: 12px; padding: 10px 12px; border-radius: 14px;
    background: rgba(244, 63, 94, 0.12); border: 1px solid rgba(244, 63, 94, 0.35);
    color: #fda4af; font-weight: 700; font-size: .88rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .mmg { gap: 10px; --mmg-gap: 9px; --mmg-radius: 15px; }
    .mmg-hud { padding: 12px; border-radius: 18px; }
    .mmg-logo { width: 38px; height: 38px; border-radius: 12px; font-size: 1rem; }
    .mmg-icon-btn { width: 40px; height: 40px; }
    .mmg-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .mmg-stat { padding: 8px; border-radius: 12px; }
    .mmg-stat label { font-size: .6rem; letter-spacing: .04em; gap: 4px; }
    .mmg-stat label i { display: none; }
    .mmg-card { padding: 10px 8px; }
    .mmg-howto { grid-template-columns: 1fr; }
    .mmg-panel { padding: 22px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .mmg *, .mmg *::before, .mmg-overlay { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Keyframes ---------- */
@keyframes mmgFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mmgDeal {
    from { opacity: 0; transform: translateY(18px) scale(.9) rotate(-2deg); }
    to { opacity: 1; transform: none; }
}
@keyframes mmgMatch {
    0% { transform: scale(1.03); }
    40% { transform: scale(1.12); }
    100% { transform: scale(1); }
}
@keyframes mmgShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px) rotate(-1deg); }
    40% { transform: translateX(7px) rotate(1deg); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(3px); }
}
@keyframes mmgBump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes mmgPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.0); } 50% { box-shadow: 0 0 0 6px rgba(244, 63, 94, 0.2); } }
@keyframes mmgRise {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); }
    20% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}
@keyframes mmgPanel { from { opacity: 0; transform: translateY(24px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes mmgStar { to { transform: scale(1); } }

.mmg-card-num {
    position: absolute; top: 6px; left: 8px; z-index: 2;
    min-width: 28px; height: 28px; padding: 0 7px; box-sizing: border-box;
    border-radius: 14px; background: rgba(99, 102, 241, 0.95); color: #fff;
    font-size: 1rem; font-weight: 700; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
[dir="rtl"] .mmg-card-num, .mmg[dir="rtl"] .mmg-card-num { left: auto; right: 8px; }

.mmg-goal { margin: 10px 0 14px; padding: 12px 14px; border-radius: 14px; background: rgba(99, 102, 241, 0.14); border: 1px solid rgba(99, 102, 241, 0.4); text-align: start; }
.mmg-goal label { display: block; font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; opacity: .75; margin-bottom: 4px; }
.mmg-goal p { margin: 0 0 6px; font-size: 1.1rem; font-weight: 700; line-height: 1.35; }
.mmg-goal small { opacity: .8; }
.mmg-howto b { display: inline-flex; width: 22px; height: 22px; margin-inline-end: 8px; border-radius: 50%; background: rgba(99, 102, 241, 0.95); color: #fff; font-size: .8rem; align-items: center; justify-content: center; }
.mmg-task { margin: 0 0 8px; padding: 8px 12px; border-radius: 12px; background: rgba(99, 102, 241, 0.14); font-weight: 600; font-size: .95rem; text-align: start; }
.mmg-task i { margin-inline-end: 6px; opacity: .8; }
