/*
GeoRankle Popup 7.1

Enhanced accessible game-over modal styling.

Used by popup.js:
- .game-over-overlay
- .game-over-modal
- .popup-close
- .popup-header
- .popup-celebration
- .popup-title
- .popup-introduction
- .popup-country-card
- .popup-flag-frame
- .popup-flag
- .popup-country-details
- .popup-country-name
- .popup-score
- .popup-score-label
- .popup-facts
- .popup-facts-grid
- .popup-fact-card
- .popup-next
- .popup-countdown
- .popup-actions
- .popup-share
- .popup-stats
- .popup-dismiss
*/

/* =========================================================
   Page state
   ========================================================= */

body.popup-open {
    overflow: hidden;
}

/* =========================================================
   Overlay
   ========================================================= */

.game-over-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;

    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% 18%,
            rgba(18, 146, 242, 0.16),
            transparent 42%
        ),
        rgba(15, 23, 42, 0.64);

    opacity: 0;

    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);

    overscroll-behavior: contain;

    transition:
        opacity 0.18s ease;
}

/*
popup.js uses .is-visible.
.is-open remains supported for older code.
*/

.game-over-overlay.is-visible,
.game-over-overlay.is-open {
    display: flex;
    opacity: 1;
}

.game-over-overlay[hidden] {
    display: none !important;
}

/* =========================================================
   Modal
   ========================================================= */

.game-over-modal {
    position: relative;

    width: min(620px, 100%);
    max-height: calc(100dvh - 48px);
    margin: auto;
    padding: 30px;

    overflow-x: hidden;
    overflow-y: auto;

    border: 1px solid rgba(255, 255, 255, 0.88);
    border-radius: 30px;

    background:
        linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.995) 0%,
            rgba(247, 251, 255, 0.99) 100%
        );

    color: #111827;
    text-align: center;

    box-shadow:
        0 34px 90px rgba(15, 23, 42, 0.38),
        0 12px 34px rgba(15, 23, 42, 0.16),
        inset 0 1px 0 #ffffff;

    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;

    animation:
        geoRanklePopupEnter
        0.32s
        cubic-bezier(0.18, 1.18, 0.35, 1)
        both;
}

.game-over-overlay.is-loss .game-over-modal {
    background:
        linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.995) 0%,
            rgba(248, 250, 252, 0.99) 100%
        );
}

.game-over-overlay.is-win .game-over-modal {
    border-color:
        rgba(255, 223, 80, 0.72);

    box-shadow:
        0 34px 90px rgba(15, 23, 42, 0.38),
        0 12px 34px rgba(255, 196, 0, 0.12),
        inset 0 1px 0 #ffffff;
}

.game-over-modal:focus {
    outline: none;
}

.game-over-modal:focus-visible {
    outline:
        3px solid rgba(37, 99, 235, 0.38);

    outline-offset: 4px;
}

.game-over-modal::-webkit-scrollbar {
    width: 8px;
}

.game-over-modal::-webkit-scrollbar-track {
    background: transparent;
}

.game-over-modal::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;

    background: #cbd5e1;
    background-clip: padding-box;
}

.game-over-modal::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
    background-clip: padding-box;
}

/* =========================================================
   Close button
   ========================================================= */

.popup-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.16);
    border-radius: 999px;

    appearance: none;
    -webkit-appearance: none;

    background:
        rgba(226, 232, 240, 0.78);

    color: #475569;

    font: inherit;
    font-size: 27px;
    font-weight: 700;
    line-height: 1;

    cursor: pointer;

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.78);

    transition:
        transform 0.18s ease,
        background-color 0.18s ease,
        color 0.18s ease,
        box-shadow 0.18s ease;
}

.popup-close:hover {
    background: #e2e8f0;
    color: #111827;

    box-shadow:
        0 5px 14px rgba(15, 23, 42, 0.1),
        inset 0 1px 0 #ffffff;

    transform:
        scale(1.06);
}

.popup-close:active {
    transform:
        scale(0.96);
}

.popup-close:focus {
    outline: none;
}

.popup-close:focus-visible {
    outline:
        3px solid rgba(37, 99, 235, 0.4);

    outline-offset: 3px;
}

/* =========================================================
   Header
   ========================================================= */

.popup-header {
    display: flex;
    flex-direction: column;
    align-items: center;

    margin: 0 44px 22px;
}

.popup-celebration {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 64px;
    height: 64px;
    margin: 0 0 10px;

    border: 1px solid #fde68a;
    border-radius: 20px;

    background:
        linear-gradient(
            180deg,
            #fff9d8,
            #fff1a6
        );

    font-size: 34px;
    line-height: 1;

    box-shadow:
        0 9px 22px rgba(245, 196, 0, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.is-loss .popup-celebration {
    border-color: #dbeafe;

    background:
        linear-gradient(
            180deg,
            #f2f8ff,
            #e6f1ff
        );

    box-shadow:
        0 9px 22px rgba(37, 99, 235, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.popup-title {
    margin: 0;

    color: #111827;

    font-size: 32px;
    font-weight: 900;
    line-height: 1.12;
}

.popup-introduction {
    margin: 8px 0 0;

    color: #64748b;

    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
}

/* =========================================================
   Country card
   ========================================================= */

.popup-country-card {
    display: grid;
    grid-template-columns: 172px minmax(0, 1fr);
    align-items: center;
    gap: 20px;

    width: 100%;
    margin: 0 0 24px;
    padding: 18px;

    border: 1px solid #e2e8f0;
    border-radius: 22px;

    background:
        linear-gradient(
            180deg,
            #ffffff,
            #f5f9fd
        );

    text-align: left;

    box-shadow:
        0 9px 24px rgba(15, 23, 42, 0.065),
        inset 0 1px 0 #ffffff;
}

.popup-flag-frame {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    min-height: 108px;
    padding: 8px;

    overflow: hidden;

    border: 1px solid #dbe5ef;
    border-radius: 16px;

    background:
        linear-gradient(
            180deg,
            #f8fafc,
            #edf3f8
        );
}

.popup-flag {
    display: block;

    width: 100%;
    max-width: 156px;
    height: auto;
    max-height: 100px;
    margin: 0;

    object-fit: cover;

    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 11px;

    background: #f8fafc;

    box-shadow:
        0 8px 20px rgba(15, 23, 42, 0.16);
}

.popup-flag-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 80px;

    font-size: 54px;
    line-height: 1;
}

.popup-country-details {
    min-width: 0;
}

.popup-country-name {
    margin: 0 0 8px;

    overflow-wrap: anywhere;

    color: #111827;

    font-size: 28px;
    font-weight: 900;
    line-height: 1.16;
}

.popup-score {
    margin: 0;

    color: #c49a00;

    font-size: 38px;
    font-weight: 900;
    line-height: 1;
}

.is-loss .popup-score {
    color: #dc2626;
}

.popup-score-label {
    margin: 7px 0 0;

    color: #64748b;

    font-size: 14px;
    font-weight: 800;
    line-height: 1.3;
}

/* Compatibility with the old popup */

.popup-subtitle {
    margin: 8px 0 20px;

    color: #64748b;

    font-size: 16px;
    font-weight: 700;
    line-height: 1.45;
}

/* =========================================================
   Facts
   ========================================================= */

.popup-facts {
    width: 100%;
    margin: 0 0 22px;
}

.popup-section-title {
    margin: 0 0 12px;

    color: #334155;

    font-size: 15px;
    font-weight: 900;
    line-height: 1.25;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.popup-facts-grid {
    display: grid;
    grid-template-columns:
        repeat(5, minmax(0, 1fr));
    gap: 9px;

    width: 100%;
}

.popup-fact-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;

    min-width: 0;
    min-height: 100px;
    padding: 11px 8px;

    border: 1px solid #e1e8f0;
    border-radius: 15px;

    background:
        linear-gradient(
            180deg,
            #ffffff,
            #f5f8fc
        );

    text-align: center;

    box-shadow:
        0 5px 14px rgba(15, 23, 42, 0.045),
        inset 0 1px 0 rgba(255, 255, 255, 0.96);
}

.popup-fact-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 34px;
    height: 34px;

    border: 1px solid #dbe7f2;
    border-radius: 11px;

    background:
        linear-gradient(
            180deg,
            #fbfdff,
            #edf5fc
        );

    font-size: 17px;
    line-height: 1;
}

.popup-fact-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;

    min-width: 0;
}

.popup-fact-label {
    color: #718096;

    font-size: 9px;
    font-weight: 800;
    line-height: 1.15;
}

.popup-fact-value {
    max-width: 100%;

    overflow-wrap: anywhere;

    color: #1f2937;

    font-size: 12px;
    font-weight: 900;
    line-height: 1.15;
}

/* =========================================================
   Next puzzle
   ========================================================= */

.popup-next {
    display: flex;
    flex-direction: column;
    align-items: center;

    width: 100%;
    margin: 0 0 20px;
    padding: 15px 18px;

    border: 1px solid #dbeafe;
    border-radius: 17px;

    background:
        linear-gradient(
            180deg,
            #f4f9ff,
            #eaf4ff
        );

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.popup-next-label {
    color: #475569;

    font-size: 12px;
    font-weight: 900;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.55px;
}

.popup-countdown {
    margin: 5px 0;

    color: #1665a9;

    font-variant-numeric: tabular-nums;

    font-size: 28px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 1px;
}

.popup-next-helper,
.popup-tomorrow {
    margin: 0;

    color: #64748b;

    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
}

/* =========================================================
   Actions
   ========================================================= */

.popup-actions {
    display: grid;
    grid-template-columns:
        minmax(0, 1.3fr)
        minmax(0, 1fr)
        minmax(0, 0.75fr);
    gap: 10px;

    width: 100%;
}

.popup-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 0;
    min-height: 50px;
    margin: 0;
    padding: 11px 15px;

    border-radius: 15px;

    appearance: none;
    -webkit-appearance: none;

    font: inherit;
    font-size: 15px;
    font-weight: 900;
    line-height: 1.15;
    text-align: center;

    cursor: pointer;

    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        border-color 0.18s ease,
        background-color 0.18s ease,
        filter 0.18s ease,
        opacity 0.18s ease;
}

/* Primary share button */

.popup-share,
.popup-primary-action {
    border: 1px solid #f2c600;

    background:
        linear-gradient(
            180deg,
            #ffe866 0%,
            #ffd400 60%,
            #ffc400 100%
        );

    color: #211c00;

    box-shadow:
        0 9px 18px rgba(255, 208, 0, 0.24),
        inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.popup-share:hover:not(:disabled),
.popup-primary-action:hover:not(:disabled) {
    filter: brightness(1.02);

    transform:
        translateY(-2px);

    box-shadow:
        0 13px 24px rgba(255, 208, 0, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

/* Statistics button */

.popup-stats,
.popup-secondary-action {
    border: 1px solid #bfdbfe;

    background:
        linear-gradient(
            180deg,
            #eff7ff,
            #dceeff
        );

    color: #155e9b;

    box-shadow:
        0 7px 16px rgba(37, 99, 235, 0.1),
        inset 0 1px 0 #ffffff;
}

.popup-stats:hover:not(:disabled),
.popup-secondary-action:hover:not(:disabled) {
    border-color: #93c5fd;

    background:
        linear-gradient(
            180deg,
            #e5f2ff,
            #cee7ff
        );

    transform:
        translateY(-2px);
}

/* Close action */

.popup-dismiss,
.popup-tertiary-action {
    border: 1px solid #d7dee8;

    background:
        linear-gradient(
            180deg,
            #ffffff,
            #f0f4f8
        );

    color: #475569;

    box-shadow:
        0 6px 14px rgba(15, 23, 42, 0.065),
        inset 0 1px 0 #ffffff;
}

.popup-dismiss:hover:not(:disabled),
.popup-tertiary-action:hover:not(:disabled) {
    border-color: #cbd5e1;
    color: #1f2937;

    transform:
        translateY(-2px);
}

.popup-actions button:active:not(:disabled) {
    transform:
        translateY(0)
        scale(0.98);
}

.popup-actions button:focus {
    outline: none;
}

.popup-actions button:focus-visible {
    outline:
        3px solid rgba(37, 99, 235, 0.38);

    outline-offset: 3px;
}

.popup-actions button:disabled {
    cursor: not-allowed;

    filter:
        saturate(0.6);

    opacity: 0.7;
    transform: none;
}

/* Share feedback */

.popup-share.is-copied,
.popup-share.is-success {
    border-color: #22c55e;

    background:
        linear-gradient(
            180deg,
            #86efac,
            #22c55e
        );

    color: #052e16;

    box-shadow:
        0 9px 20px rgba(34, 197, 94, 0.22);
}

.popup-share.has-error,
.popup-share.is-error {
    border-color: #ef4444;

    background:
        linear-gradient(
            180deg,
            #fecaca,
            #ef4444
        );

    color: #450a0a;

    box-shadow:
        0 9px 20px rgba(239, 68, 68, 0.2);
}

/* =========================================================
   Entry animation
   ========================================================= */

@keyframes geoRanklePopupEnter {
    from {
        opacity: 0;

        transform:
            translateY(18px)
            scale(0.93);
    }

    to {
        opacity: 1;

        transform:
            translateY(0)
            scale(1);
    }
}

/* =========================================================
   Tablet
   ========================================================= */

@media (max-width: 700px) {
    .game-over-overlay {
        padding: 16px;
    }

    .game-over-modal {
        width: min(540px, 100%);
        max-height: calc(100dvh - 32px);
        padding: 27px 22px 23px;

        border-radius: 25px;
    }

    .popup-country-card {
        grid-template-columns: 145px minmax(0, 1fr);
        gap: 16px;
    }

    .popup-facts-grid {
        grid-template-columns:
            repeat(3, minmax(0, 1fr));
    }

    .popup-actions {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    .popup-dismiss,
    .popup-tertiary-action {
        grid-column: 1 / -1;
    }
}

/* =========================================================
   Mobile
   ========================================================= */

@media (max-width: 520px) {
    .game-over-overlay {
        align-items: flex-start;

        padding: 10px;
    }

    .game-over-modal {
        width: 100%;
        max-height: calc(100dvh - 20px);
        margin: auto 0;
        padding: 24px 15px 18px;

        border-radius: 21px;
    }

    .popup-close {
        top: 10px;
        right: 11px;

        width: 36px;
        height: 36px;

        font-size: 24px;
    }

    .popup-header {
        margin:
            0 36px 18px;
    }

    .popup-celebration {
        width: 56px;
        height: 56px;

        border-radius: 17px;

        font-size: 29px;
    }

    .popup-title {
        font-size: 27px;
    }

    .popup-introduction {
        font-size: 14px;
    }

    .popup-country-card {
        grid-template-columns:
            minmax(0, 1fr);

        gap: 13px;

        margin-bottom: 20px;
        padding: 14px;

        text-align: center;
    }

    .popup-flag-frame {
        width: min(210px, 100%);
        min-height: 100px;
        margin: 0 auto;
    }

    .popup-flag {
        max-width: 150px;
        max-height: 94px;
    }

    .popup-country-name {
        margin-bottom: 7px;

        font-size: 24px;
    }

    .popup-score {
        font-size: 33px;
    }

    .popup-facts {
        margin-bottom: 18px;
    }

    .popup-facts-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));

        gap: 8px;
    }

    .popup-fact-card {
        min-height: 91px;
        padding: 10px 7px;

        border-radius: 13px;
    }

    .popup-facts-grid
    .popup-fact-card:last-child {
        grid-column: 1 / -1;
    }

    .popup-next {
        margin-bottom: 17px;
        padding: 13px 14px;

        border-radius: 15px;
    }

    .popup-countdown {
        font-size: 25px;
    }

    .popup-actions {
        grid-template-columns:
            minmax(0, 1fr);

        gap: 9px;
    }

    .popup-dismiss,
    .popup-tertiary-action {
        grid-column: auto;
    }

    .popup-actions button {
        min-height: 48px;
    }
}

/* =========================================================
   Small mobile
   ========================================================= */

@media (max-width: 360px) {
    .game-over-modal {
        padding:
            22px 12px 16px;
    }

    .popup-title {
        font-size: 25px;
    }

    .popup-country-name {
        font-size: 22px;
    }

    .popup-facts-grid {
        grid-template-columns:
            minmax(0, 1fr);
    }

    .popup-facts-grid
    .popup-fact-card:last-child {
        grid-column: auto;
    }

    .popup-fact-card {
        display: grid;
        grid-template-columns:
            36px minmax(0, 1fr);

        min-height: 62px;

        text-align: left;
    }

    .popup-fact-text {
        align-items: flex-start;
    }

    .popup-fact-label {
        font-size: 10px;
    }

    .popup-fact-value {
        font-size: 13px;
    }
}

/* =========================================================
   High contrast
   ========================================================= */

@media (prefers-contrast: more) {
    .game-over-overlay {
        background:
            rgba(0, 0, 0, 0.78);
    }

    .game-over-modal,
    .popup-country-card,
    .popup-fact-card,
    .popup-next {
        border-width: 2px;
        border-color: #64748b;
    }

    .popup-close,
    .popup-actions button {
        border-width: 2px;
    }
}

/* =========================================================
   Reduced motion
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    .game-over-overlay,
    .game-over-modal,
    .popup-close,
    .popup-country-card,
    .popup-actions button {
        transition: none;
        animation: none;
    }

    .popup-close:hover,
    .popup-country-card:hover,
    .popup-actions button:hover,
    .popup-actions button:active {
        transform: none;
    }
}