/*
GeoRankle Statistics Modal 1.0

Compact topbar entry point and accessible statistics overlay.
*/

body.stats-open {
    overflow: hidden;
}

/* =========================================================
   Topbar controls
   ========================================================= */

.game-topbar {
    grid-template-columns:
        auto
        minmax(0, 1fr)
        auto;
}

.game-topbar-right {
    position: relative;
    z-index: 8;

    grid-column: 3;
    grid-row: 1;

    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.game-topbar-right .sound-toggle {
    grid-column: auto;
    grid-row: auto;
}

.stats-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 46px;
    height: 46px;
    margin: 0;
    padding: 0;

    border: 1px solid #c7d2fe;
    border-radius: 15px;

    appearance: none;
    -webkit-appearance: none;

    background:
        linear-gradient(
            180deg,
            #ffffff,
            #eef2ff
        );

    color: #4338ca;
    cursor: pointer;

    font-size: 20px;
    line-height: 1;

    box-shadow:
        0 8px 20px rgba(67, 56, 202, 0.11),
        inset 0 1px 0 #ffffff;

    transition:
        transform 0.16s ease,
        border-color 0.16s ease,
        box-shadow 0.16s ease;
}

.stats-button:hover {
    border-color: #818cf8;
    transform: translateY(-2px);

    box-shadow:
        0 11px 24px rgba(67, 56, 202, 0.18),
        inset 0 1px 0 #ffffff;
}

.stats-button:active {
    transform: translateY(1px);
}

.stats-button:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.3);
    outline-offset: 3px;
}

/* =========================================================
   Overlay and modal
   ========================================================= */

.stats-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100001;

    display: none;
    align-items: center;
    justify-content: center;

    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;

    overflow-x: hidden;
    overflow-y: auto;

    background:
        radial-gradient(
            circle at 50% 10%,
            rgba(99, 102, 241, 0.24),
            transparent 42%
        ),
        rgba(15, 23, 42, 0.72);

    opacity: 0;

    -webkit-backdrop-filter: blur(11px);
    backdrop-filter: blur(11px);

    overscroll-behavior: contain;

    transition: opacity 0.18s ease;
}

.stats-modal-overlay.is-visible {
    display: flex;
    opacity: 1;
}

.stats-modal-overlay[hidden] {
    display: none !important;
}

.stats-modal {
    position: relative;

    width: min(1040px, 100%);
    max-height: calc(100dvh - 48px);
    margin: auto;
    padding: 30px;

    overflow-x: hidden;
    overflow-y: auto;

    border: 1px solid rgba(255, 255, 255, 0.92);
    border-radius: 30px;

    background:
        linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.998),
            rgba(246, 249, 255, 0.995)
        );

    color: #111827;

    box-shadow:
        0 36px 94px rgba(15, 23, 42, 0.46),
        0 12px 34px rgba(15, 23, 42, 0.18),
        inset 0 1px 0 #ffffff;

    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;

    animation:
        geoRankleStatsModalEnter
        0.3s
        cubic-bezier(0.18, 1.16, 0.35, 1)
        both;
}

.stats-modal::-webkit-scrollbar {
    width: 8px;
}

.stats-modal::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: #cbd5e1;
    background-clip: padding-box;
}

.stats-modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    z-index: 5;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;

    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 999px;

    appearance: none;
    -webkit-appearance: none;

    background: rgba(226, 232, 240, 0.82);
    color: #475569;
    cursor: pointer;

    font: inherit;
    font-size: 27px;
    font-weight: 800;
    line-height: 1;

    transition:
        transform 0.16s ease,
        background-color 0.16s ease,
        color 0.16s ease;
}

.stats-modal-close:hover {
    background: #e0e7ff;
    color: #3730a3;
    transform: rotate(4deg) scale(1.04);
}

.stats-modal-close:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.34);
    outline-offset: 3px;
}

/* =========================================================
   Modal header and statistics content
   ========================================================= */

.stats-modal-header {
    display: flex;
    align-items: center;
    gap: 15px;

    margin: 0 48px 24px 0;
}

.stats-modal-header-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;

    width: 58px;
    height: 58px;

    border: 1px solid #c7d2fe;
    border-radius: 18px;

    background:
        linear-gradient(
            180deg,
            #ffffff,
            #eef2ff
        );

    font-size: 29px;
    line-height: 1;

    box-shadow:
        0 10px 24px rgba(67, 56, 202, 0.12),
        inset 0 1px 0 #ffffff;
}

.stats-modal-heading {
    min-width: 0;
}

.stats-modal-title {
    margin: 0;

    color: #111827;

    font-size: 30px;
    font-weight: 900;
    line-height: 1.1;
}

.stats-modal-introduction {
    margin: 5px 0 0;

    color: #64748b;

    font-size: 14px;
    font-weight: 800;
    line-height: 1.35;
}

.stats-modal-content {
    width: 100%;
    min-width: 0;
}

.stats-modal-content .stats-summary {
    margin-top: 0;
}

@keyframes geoRankleStatsModalEnter {
    from {
        opacity: 0;
        transform:
            translateY(12px)
            scale(0.975);
    }

    to {
        opacity: 1;
        transform:
            translateY(0)
            scale(1);
    }
}

/* =========================================================
   Responsive layout
   ========================================================= */

@media (max-width: 700px) {
    .game-topbar {
        grid-template-columns:
            minmax(0, 1fr)
            auto
            minmax(0, 1fr);
        row-gap: 14px;
    }

    .game-topbar .game-badge {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .game-topbar-left {
        grid-column: 1;
        grid-row: 2;
        justify-self: start;
    }

    .game-topbar-right {
        grid-column: 3;
        grid-row: 2;
        justify-self: end;
    }

    .stats-modal-overlay {
        padding: 14px;
    }

    .stats-modal {
        max-height: calc(100dvh - 28px);
        padding: 26px 20px 21px;

        border-radius: 24px;
    }
}

@media (max-width: 500px) {
    .stats-button {
        width: 42px;
        height: 42px;

        border-radius: 13px;

        font-size: 19px;
    }

    .stats-modal-overlay {
        align-items: flex-start;
        padding: 0;
    }

    .stats-modal {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        padding: 20px 10px 18px;

        border: 0;
        border-radius: 0;
    }

    .stats-modal-close {
        position: fixed;
        top: 10px;
        right: 10px;

        width: 38px;
        height: 38px;

        font-size: 25px;
    }

    .stats-modal-header {
        margin: 0 44px 18px 4px;
    }

    .stats-modal-header-icon {
        width: 52px;
        height: 52px;

        border-radius: 16px;

        font-size: 26px;
    }

    .stats-modal-title {
        font-size: 25px;
    }

    .stats-modal-introduction {
        font-size: 12px;
    }

    .stats-modal-content .stats-summary {
        margin-top: 0;
        padding: 12px;

        border-radius: 18px;
    }
}

@media (prefers-color-scheme: dark) {
    .stats-modal {
        border-color: #334155;

        background:
            linear-gradient(
                180deg,
                #111827,
                #0f172a
            );

        color: #f8fafc;
    }

    .stats-modal-title {
        color: #f8fafc;
    }

    .stats-modal-introduction {
        color: #cbd5e1;
    }

    .stats-modal-close {
        border-color: #475569;
        background: #1e293b;
        color: #e2e8f0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .stats-button,
    .stats-modal-overlay,
    .stats-modal,
    .stats-modal-close {
        animation: none;
        transition: none;
    }
}
