﻿/* Full-screen matchmaking flow: search -> VS intro -> lobby -> countdown */
.mm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    background: radial-gradient(ellipse at center, #1c2433 0%, #0b0d12 75%);
    animation: mm-fade 0.25s ease both;
}

.mm-screen {
    position: relative;
    width: 100%;
    max-width: 440px;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 16px;
    color: #fff;
}

.mm-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 20;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.mm-close:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: rotate(90deg);
}

.mm-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 100%;
    text-align: center;
}

.mm-hint {
    margin: 0;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
}

.mm-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.mm-btn {
    padding: 10px 20px;
    border: 2px solid var(--sc-primary);
    border-radius: 999px;
    background: var(--sc-primary);
    color: var(--sc-bg);
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.mm-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 14px rgba(var(--sc-primary-rgb), 0.5);
}

.mm-btn:active {
    transform: scale(0.96);
}

.mm-btn-secondary {
    background: transparent;
    color: var(--sc-primary);
}

.mm-btn-small {
    padding: 6px 14px;
    font-size: 13px;
}

.mm-ended-icon {
    font-size: 56px;
    color: var(--sc-primary);
    animation: mm-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.mm-fade-in {
    animation: mm-fade 0.3s ease both;
}

/* Searching: radar pulse around the player's avatar */
.mm-radar {
    position: relative;
    width: 180px;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.mm-radar-ring {
    position: absolute;
    inset: 0;
    border: 2px solid var(--sc-primary);
    border-radius: 50%;
    opacity: 0;
    animation: mm-radar 2.4s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}

.mm-radar-ring:nth-child(3) {
    animation-delay: 0.8s;
}

.mm-radar-ring:nth-child(4) {
    animation-delay: 1.6s;
}

/* Rotating scan beam behind the rings */
.mm-radar-sweep {
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, rgba(var(--sc-primary-rgb), 0.35), transparent 70deg, transparent);
    animation: mm-spin 2.4s linear infinite;
}

/* Match found: rings and beam flash green and burst outward */
.mm-radar.is-found .mm-radar-ring {
    border-color: #4cd97b;
    animation: mm-radar-burst 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.mm-radar.is-found .mm-radar-ring:nth-child(3) {
    animation-delay: 0.1s;
}

.mm-radar.is-found .mm-radar-ring:nth-child(4) {
    animation-delay: 0.2s;
}

.mm-radar.is-found .mm-radar-sweep {
    background: radial-gradient(circle, rgba(76, 217, 123, 0.45), transparent 70%);
    animation: mm-fade 0.3s ease both;
}

.mm-radar.is-found .mm-radar-avatar {
    border-color: #4cd97b;
    box-shadow: 0 0 32px rgba(76, 217, 123, 0.7);
    animation: mm-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.mm-found-title {
    color: #4cd97b;
    animation: mm-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.mm-radar-avatar {
    position: relative;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--sc-primary);
    box-shadow: 0 0 24px rgba(var(--sc-primary-rgb), 0.45);
    animation: mm-breathe 2.4s ease-in-out infinite;
}

.mm-search-title {
    margin: 0;
    font-weight: bold;
}

.mm-search-time {
    font-size: 28px;
    font-variant-numeric: tabular-nums;
    color: var(--sc-primary);
}

.mm-progress {
    width: 220px;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.mm-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--sc-primary), #ffcc00);
    transition: width 1s linear;
}

.mm-dots span {
    animation: mm-dot 1.4s infinite both;
}

.mm-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.mm-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* VS intro: banners slam in from either side */
.mm-intro {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    min-height: 100%;
}

.mm-intro-side {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 22px 12px;
    border-radius: 16px;
    background-size: cover;
    background-position: center;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.mm-intro-side::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 18, 0.55);
}

.mm-intro-side > * {
    position: relative;
}

.mm-intro-left {
    animation: mm-slam-left 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.mm-intro-right {
    animation: mm-slam-right 0.55s cubic-bezier(0.22, 1, 0.36, 1) 0.12s both;
}

.mm-intro-avatar {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--sc-primary);
}

.mm-intro-right .mm-intro-avatar {
    border-color: #ff7a6b;
}

.mm-intro-name {
    margin-top: 6px;
    font-size: 22px;
    font-weight: bold;
}

.mm-intro-title {
    font-size: 13px;
    color: #ffcc00;
}

.mm-intro-vs {
    align-self: center;
    font-size: 56px;
    font-weight: 900;
    font-style: italic;
    line-height: 1;
    color: #ffcc00;
    text-shadow: 0 0 18px rgba(255, 204, 0, 0.6), 3px 3px 0 #b33a2b;
    animation: mm-vs-slam 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.45s both,
               mm-shake 0.3s ease 0.9s;
}

.mm-intro-notice {
    margin: 0;
    text-align: center;
    color: #ffcc00;
    animation: mm-fade 0.4s ease 0.9s both;
}

/* Lobby */
.mm-lobby {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 30px;
}

.mm-lobby-mode {
    position: absolute;
    top: 6px;
    left: 2px;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
}

.mm-lobby-vs {
    align-self: center;
    margin: -14px 0;
    z-index: 3;
    font-size: 26px;
    font-weight: 900;
    font-style: italic;
    color: #ffcc00;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5), 2px 2px 0 #b33a2b;
    animation: mm-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s both;
}

/* Both players locked in: panels charge up while the countdown runs */
.mm-lobby.is-locked .mm-panel {
    animation: mm-charge 1s ease-in-out infinite;
}

.mm-stalled {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 204, 0, 0.4);
    border-radius: 12px;
    background: rgba(255, 204, 0, 0.08);
    font-size: 13px;
    color: #ffcc00;
    animation: mm-enter-bottom 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.mm-enter-top {
    animation: mm-enter-top 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.mm-enter-bottom {
    /* Backwards only: a transform left on after the entrance would trap the roster's fixed details sheet in the panel */
    animation: mm-enter-bottom 0.45s cubic-bezier(0.22, 1, 0.36, 1) 0.08s backwards;
}

/* Countdown: each number zooms in fresh (keyed in markup) */
.mm-countdown {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none; /* Keep the "Wait!" button usable */
    animation: mm-fade 0.2s ease both;
}

/* Shockwave that expands behind each number */
.mm-countdown-ring {
    position: absolute;
    width: 160px;
    height: 160px;
    border: 4px solid rgba(var(--sc-primary-rgb), 0.8);
    border-radius: 50%;
    animation: mm-shockwave 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.mm-countdown-value {
    position: relative;
    font-size: 120px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 30px rgba(var(--sc-primary-rgb), 0.8), 4px 4px 0 #1E3A5F;
    animation: mm-count 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.mm-countdown-value.is-fight {
    font-size: 84px;
    font-style: italic;
    color: #ffcc00;
    text-shadow: 0 0 30px rgba(255, 204, 0, 0.8), 4px 4px 0 #b33a2b;
    animation: mm-vs-slam 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both, mm-shake 0.3s ease 0.4s;
}

@keyframes mm-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes mm-radar {
    0% {
        transform: scale(0.45);
        opacity: 0.9;
    }
    100% {
        transform: scale(1.15);
        opacity: 0;
    }
}

@keyframes mm-radar-burst {
    from {
        transform: scale(0.5);
        opacity: 1;
    }
    to {
        transform: scale(1.6);
        opacity: 0;
    }
}

@keyframes mm-shockwave {
    from {
        transform: scale(0.3);
        opacity: 1;
    }
    to {
        transform: scale(2.4);
        opacity: 0;
    }
}

@keyframes mm-charge {
    0%, 100% { box-shadow: 0 0 12px rgba(76, 217, 123, 0.35); }
    50% { box-shadow: 0 0 28px rgba(76, 217, 123, 0.75), inset 0 0 18px rgba(76, 217, 123, 0.2); }
}

@keyframes mm-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes mm-dot {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}

@keyframes mm-pop {
    from {
        opacity: 0;
        transform: scale(0.4);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes mm-slam-left {
    from {
        opacity: 0;
        transform: translateX(-110%) skewX(-12deg);
    }
    to {
        opacity: 1;
        transform: translateX(0) skewX(0);
    }
}

@keyframes mm-slam-right {
    from {
        opacity: 0;
        transform: translateX(110%) skewX(12deg);
    }
    to {
        opacity: 1;
        transform: translateX(0) skewX(0);
    }
}

@keyframes mm-vs-slam {
    from {
        opacity: 0;
        transform: scale(3) rotate(-10deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0);
    }
}

@keyframes mm-shake {
    0%, 100% { translate: 0 0; }
    25% { translate: -4px 2px; }
    50% { translate: 4px -2px; }
    75% { translate: -2px -2px; }
}

@keyframes mm-enter-top {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes mm-enter-bottom {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes mm-count {
    0% {
        opacity: 0;
        transform: scale(2.2);
    }
    35% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0.15;
        transform: scale(0.85);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mm-overlay *, .mm-overlay *::before, .mm-overlay *::after,
    .mm-menu *, .mm-menu *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        animation-delay: 0s !important;
        transition-duration: 0.01ms !important;
    }
}

@keyframes mm-spin {
    to { transform: rotate(360deg); }
}

/* Scrolling inside the battle overlay never drags the page behind it (iOS rubber-banding) */
.mm-overlay {
    overscroll-behavior: contain;
}

/* While a battle is open the app's bars step aside, so the battle owns the whole screen (see BattleSelector) */
body.is-battling .app-topbar,
body.is-battling .tabbar {
    display: none;
}

body.is-battling .mm-overlay {
    z-index: 2000;
    padding-top: var(--sc-safe-top);
}
