/* ═══════════════════════════════════════════════════════════════
   Multiplayer — Create Room pop-up & lobby: refreshed style + motion
   Loaded after multiplayer.css / polish.css / popups.css.
   All motion is disabled for users who prefer reduced motion.
   ═══════════════════════════════════════════════════════════════ */

/* ── Entrance ───────────────────────────────────────────────── */
.overlay-base:has(.room-config-box) { animation: fxFade .3s ease both; }
.room-config-box {
    animation: fxRise .55s cubic-bezier(.2, .9, .25, 1.15) both !important;
    border-radius: 28px;
    padding: 0 !important;
}
@keyframes fxFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fxRise {
    from { opacity: 0; transform: translateY(34px) scale(.95); }
    to   { opacity: 1; transform: none; }
}

/* ── Header: living gradient, sparkles, floating lock ──────── */
html body .room-config-head {
    background: linear-gradient(120deg, #0F1E3A, #1B325E 30%, #3B5A92 60%, #1B325E) !important; /* brand navy only */
    background-size: 260% 260% !important;
    animation: fxGradient 9s ease-in-out infinite;
    padding: 28px 28px 22px !important;
}
@keyframes fxGradient {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
}
.room-config-head::before {
    content: "";
    position: absolute; inset: -40%;
    background:
        radial-gradient(3px 3px at 12% 30%, rgba(255,255,255,.9), transparent 60%),
        radial-gradient(2px 2px at 28% 70%, rgba(255,255,255,.7), transparent 60%),
        radial-gradient(3px 3px at 52% 18%, rgba(255,255,255,.8), transparent 60%),
        radial-gradient(2px 2px at 70% 64%, rgba(255,255,255,.7), transparent 60%),
        radial-gradient(3px 3px at 88% 34%, rgba(255,255,255,.9), transparent 60%),
        radial-gradient(2px 2px at 40% 48%, rgba(255,255,255,.6), transparent 60%);
    animation: fxDrift 14s linear infinite;
    opacity: .75;
    pointer-events: none;
}
@keyframes fxDrift {
    from { transform: translate3d(0, 0, 0); }
    to   { transform: translate3d(-8%, -12%, 0); }
}
.room-config-emoji {
    width: 64px; height: 64px;
    display: inline-grid !important; place-items: center;
    font-size: 30px !important;
    border-radius: 20px;
    background: rgba(255,255,255,.16);
    border: 1px solid rgba(255,255,255,.28);
    box-shadow: 0 10px 26px -10px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.3);
    margin-bottom: 10px;
    animation: fxFloat 3.2s ease-in-out infinite;
    position: relative;
}
.room-config-emoji::after {
    content: "";
    position: absolute; inset: -6px;
    border-radius: 24px;
    border: 2px solid rgba(255,255,255,.35);
    animation: fxRing 2.4s ease-out infinite;
}
@keyframes fxFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes fxRing  { from { opacity: .8; transform: scale(.92); } to { opacity: 0; transform: scale(1.25); } }
.room-config-box .matchmaking-title { font-size: 1.45rem; letter-spacing: -.01em; }

/* ── Step numbers on section labels ────────────────────────── */
.room-config-body { counter-reset: fxstep; padding-top: 18px !important; }
.room-config-body > .config-section:not([hidden]) > .config-label::before {
    counter-increment: fxstep;
    content: counter(fxstep);
    display: inline-grid; place-items: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    font-size: .72rem; font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #3B5A92, #4f7df0);
    margin-right: 2px;
}
.room-config-body > .config-section {
    animation: fxSlide .45s ease both;
}
.room-config-body > .config-section:nth-child(2) { animation-delay: .06s; }
.room-config-body > .config-section:nth-child(3) { animation-delay: .12s; }
.room-config-body > .config-section:nth-child(4) { animation-delay: .18s; }
.room-config-body > .config-section:nth-child(5) { animation-delay: .24s; }
@keyframes fxSlide { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ── Source toggle: segmented control with a sliding pill ──── */
.source-toggle {
    position: relative;
    gap: 0 !important;
    padding: 5px;
    border-radius: 16px;
    background: var(--primary-bg);
    box-shadow: var(--neumorphic-inset);
}
.source-toggle::before {
    content: "";
    position: absolute;
    top: 5px; bottom: 5px; left: 5px;
    width: calc(50% - 5px);
    border-radius: 12px;
    background: linear-gradient(135deg, #1B325E, #3B5A92);
    box-shadow: 0 8px 20px -8px rgba(59, 90, 146, .7);
    transition: transform .45s cubic-bezier(.2, .9, .25, 1.2);
}
.source-toggle:has(.source-btn[data-source="custom"].is-picked)::before { transform: translateX(100%); }
.source-toggle .source-btn,
.source-toggle .source-btn.is-picked,
.source-toggle .source-btn:hover {
    position: relative; z-index: 1;
    background: transparent !important;
    box-shadow: none !important;
    border-color: transparent !important;
    transform: none !important;
    transition: color .3s ease;
}
.source-toggle .source-btn.is-picked { color: #fff; }

/* ── Topic chips become picture tiles ──────────────────────── */
.room-config-box .topic-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 10px;
}
.room-config-box .topic-chip.fx-tile {
    position: relative;
    overflow: hidden;
    padding: 0;
    aspect-ratio: 4 / 3;
    justify-content: flex-end;
    align-items: stretch;
    border: 0;
    border-radius: 16px;
    color: #fff;
    background: #1B325E;
    box-shadow: 0 6px 16px -8px rgba(0,0,0,.45);
    animation: fxPop .45s cubic-bezier(.2, .9, .25, 1.25) both;
    animation-delay: calc(var(--i, 0) * 28ms + .15s);
}
@keyframes fxPop { from { opacity: 0; transform: scale(.82) translateY(8px); } to { opacity: 1; transform: none; } }
.topic-chip.fx-tile .fx-tile-img {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform .5s ease, filter .3s ease;
}
.topic-chip.fx-tile::before {
    content: "";
    position: absolute; inset: 0; z-index: 1;
    background: linear-gradient(180deg, rgba(10,16,34,.05) 30%, rgba(10,16,34,.82) 100%);
    transition: background .3s ease;
}
.topic-chip.fx-tile > span {
    position: relative; z-index: 2;
    text-shadow: 0 1px 6px rgba(0,0,0,.6);
}
.topic-chip.fx-tile .topic-emoji {
    position: absolute; top: 8px; left: 8px;
    width: 30px; height: 30px;
    display: grid; place-items: center;
    font-size: 1rem !important;
    border-radius: 10px;
    background: rgba(255,255,255,.2);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.topic-chip.fx-tile > span:last-of-type {
    display: block;
    padding: 0 10px 9px;
    text-align: left;
    font-size: .76rem;
    line-height: 1.25;
}
.topic-chip.fx-tile:hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 14px 26px -12px rgba(0,0,0,.55) !important;
}
.topic-chip.fx-tile:hover .fx-tile-img { transform: scale(1.08); }
.topic-chip.fx-tile.selected {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #3B5A92, 0 14px 30px -10px rgba(59,90,146,.8) !important;
    transform: translateY(-2px);
}
.topic-chip.fx-tile.selected::before {
    background: linear-gradient(180deg, rgba(59,90,146,.25) 0%, rgba(27,50,94,.85) 100%);
}
.topic-chip.fx-tile::after {
    content: "\2713";
    position: absolute; top: 8px; right: 8px; z-index: 3;
    width: 24px; height: 24px;
    display: grid; place-items: center;
    border-radius: 50%;
    font-size: .8rem; font-weight: 800;
    color: #1B325E; background: #fff;
    transform: scale(0);
    transition: transform .35s cubic-bezier(.2, .9, .25, 1.6);
}
.topic-chip.fx-tile.selected::after { transform: scale(1); }
body.dark-mode .topic-chip.fx-tile.selected,
html.dark-mode .topic-chip.fx-tile.selected {
    box-shadow: 0 0 0 3px #1e1e2e, 0 0 0 6px #4f7df0, 0 14px 30px -10px rgba(79,125,240,.7) !important;
}

/* ── Selects: softer focus ─────────────────────────────────── */
.room-config-box .config-select { transition: box-shadow .25s ease, transform .2s ease; }
.room-config-box .config-select:hover { transform: translateY(-1px); }
.room-config-box .config-select:focus { box-shadow: var(--neumorphic-shadow), 0 0 0 3px rgba(59,90,146,.35); outline: none; }

/* ── Summary chips pop when their value changes ───────────── */
.summary-chip.fx-bump { animation: fxBump .45s cubic-bezier(.2, .9, .25, 1.6); }
@keyframes fxBump { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
.summary-chip--total { background: linear-gradient(135deg, #3B5A92, #4f7df0) !important; }

/* ── Footer: frosted bar, shimmering CTA, quiet cancel ────── */
.room-config-foot {
    background: color-mix(in srgb, var(--primary-bg) 82%, transparent) !important;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.room-config-foot #confirmCreateRoomBtn {
    position: relative; overflow: hidden;
    background: linear-gradient(135deg, #1B325E, #3B5A92 60%, #4f7df0) !important;
}
.room-config-foot #confirmCreateRoomBtn::after {
    content: "";
    position: absolute; top: 0; bottom: 0; left: -60%;
    width: 45%;
    background: linear-gradient(100deg, transparent, rgba(255,255,255,.35), transparent);
    transform: skewX(-18deg);
    animation: fxShine 3.2s ease-in-out infinite 1s;
}
@keyframes fxShine { 0% { left: -60%; } 45%, 100% { left: 130%; } }
.room-config-foot #confirmCreateRoomBtn:active { transform: scale(.97); }
.room-config-foot #cancelConfigBtn {
    background: transparent !important;
    color: var(--danger, #e5484d) !important;
    border: 2px solid currentColor !important;
    box-shadow: none !important;
}
.room-config-foot #cancelConfigBtn i { color: inherit !important; }
.room-config-foot #cancelConfigBtn:hover { background: rgba(229,72,77,.08) !important; }

/* Leaving animation (class added by mp-room-fx.js before removal) */
.overlay-base.fx-leaving { animation: fxFade .22s ease reverse both; }
.overlay-base.fx-leaving .room-config-box { animation: fxRise .22s ease reverse both !important; }

/* ── Private-room lobby (shown after "Create Room") ───────── */
.modal-box-sm .lobby-header-icon { animation: fxFloat 3s ease-in-out infinite; display: inline-block; }
.lobby-room-code {
    position: relative; overflow: hidden;
    animation: fxCodeGlow 2.4s ease-in-out infinite;
}
.lobby-room-code::after {
    content: "";
    position: absolute; top: 0; bottom: 0; left: -50%;
    width: 40%;
    background: linear-gradient(100deg, transparent, rgba(255,255,255,.35), transparent);
    transform: skewX(-18deg);
    animation: fxShine 2.8s ease-in-out infinite .6s;
}
@keyframes fxCodeGlow {
    0%, 100% { box-shadow: var(--neumorphic-inset), 0 0 0 0 rgba(59,90,146,0); }
    50%      { box-shadow: var(--neumorphic-inset), 0 0 22px 2px rgba(59,90,146,.35); }
}
.lobby-players .lobby-player-slot { animation: fxPop .45s cubic-bezier(.2,.9,.25,1.25) both; }
.lobby-players .lobby-player-slot:nth-child(2) { animation-delay: .08s; }
.lobby-players .lobby-player-slot:nth-child(3) { animation-delay: .16s; }
.lobby-players .lobby-player-slot:nth-child(4) { animation-delay: .24s; }
.lobby-players .lobby-player-slot:nth-child(n+5) { animation-delay: .3s; }
.lobby-player-slot.empty-slot i { animation: fxBreath 1.8s ease-in-out infinite; }
@keyframes fxBreath { 0%,100% { opacity: .35; } 50% { opacity: .9; } }

/* ── Phones: pop-up becomes a bottom sheet ─────────────────── */
@media (max-width: 600px) {
    .overlay-base:has(.room-config-box) { align-items: flex-end; padding: 0 !important; }
    .room-config-box {
        width: 100% !important; max-width: none !important; margin: 0 !important;
        max-height: 94vh !important;
        border-radius: 26px 26px 0 0 !important;
        animation: fxSheet .5s cubic-bezier(.2, .9, .25, 1.05) both !important;
    }
    html body .room-config-head { border-radius: 26px 26px 0 0 !important; padding: 22px 16px 16px !important; }
    .room-config-head::after { /* grab handle */
        background: none;
    }
    .room-config-box .room-config-head > :first-child::before {
        content: "";
        position: absolute; top: -14px; left: 50%;
        width: 42px; height: 5px; margin-left: -21px;
        border-radius: 3px; background: rgba(255,255,255,.5);
    }
    .room-config-emoji { width: 52px; height: 52px; font-size: 24px !important; border-radius: 16px; }
    .room-config-box .topic-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .topic-chip.fx-tile > span:last-of-type { font-size: .68rem; padding: 0 7px 7px; }
    .topic-chip.fx-tile .topic-emoji { width: 24px; height: 24px; font-size: .8rem !important; top: 6px; left: 6px; }
    .room-config-foot { flex-wrap: nowrap !important; }
    .room-config-foot .neumorphic-btn { flex: 1 1 0 !important; }
}
@keyframes fxSheet { from { transform: translateY(100%); } to { transform: none; } }

@media (prefers-reduced-motion: reduce) {
    .room-config-box, .room-config-head, .room-config-head::before, .room-config-emoji,
    .room-config-emoji::after, .room-config-body > .config-section, .topic-chip.fx-tile,
    .room-config-foot #confirmCreateRoomBtn::after, .lobby-room-code, .lobby-room-code::after,
    .lobby-players .lobby-player-slot, .lobby-player-slot.empty-slot i, .modal-box-sm .lobby-header-icon {
        animation: none !important;
    }
    .source-toggle::before, .topic-chip.fx-tile .fx-tile-img { transition: none; }
}
