/* Shared loading treatment for the signed-in arena and public city preview. */
.map-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fafafa;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 28px;
    z-index: 2000;
    opacity: 1;
    visibility: visible;
    contain: layout paint style;
    isolation: isolate;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    will-change: opacity;
    /* Entry must be immediate so an initializing or recovering map can never
       paint through the loader. The dismissed state owns the exit fade. */
    transition: none;
}

.map-loading-overlay.dismissed {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    will-change: auto;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.map-loading-overlay.dismissed .map-loading-cell,
.map-loading-overlay.dismissed .map-loading-cell::after {
    animation: none;
    will-change: auto;
}

.map-loading-overlay.is-page-navigation {
    cursor: wait;
}

/* 3x3 territory grid animation */
.map-loading-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    width: 72px;
    height: 72px;
    contain: layout paint style;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

.map-loading-cell {
    --sector-rgb: 0, 200, 83;
    position: relative;
    overflow: hidden;
    border-radius: 3px;
    background: rgba(var(--sector-rgb), 0.18);
}

/* A bright layer flashes over the muted base. Only its opacity changes, so
   each activation stays compositor-friendly during expensive map work. */
.map-loading-cell::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgb(var(--sector-rgb));
    opacity: 0;
    backface-visibility: hidden;
    will-change: opacity;
    animation-duration: 3.6s;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

/* Static territory colors: green (owned), red (contested), yellow (enemy). */
.map-loading-cell:nth-child(3n+1) { --sector-rgb: 0, 200, 83; }
.map-loading-cell:nth-child(3n+2) { --sector-rgb: 220, 38, 38; }
.map-loading-cell:nth-child(3n)   { --sector-rgb: 250, 204, 21; }

/* Irregular activation order: 1, 6, 7, 2, 9, 4, 5, 3, 8. Each square
   remains lit while the rest join it; after a short full-grid hold, the
   sequence fades in reverse and rests before repeating. */
.map-loading-cell:nth-child(1)::after { animation-name: sectorCascade1; }
.map-loading-cell:nth-child(2)::after { animation-name: sectorCascade2; }
.map-loading-cell:nth-child(3)::after { animation-name: sectorCascade3; }
.map-loading-cell:nth-child(4)::after { animation-name: sectorCascade4; }
.map-loading-cell:nth-child(5)::after { animation-name: sectorCascade5; }
.map-loading-cell:nth-child(6)::after { animation-name: sectorCascade6; }
.map-loading-cell:nth-child(7)::after { animation-name: sectorCascade7; }
.map-loading-cell:nth-child(8)::after { animation-name: sectorCascade8; }
.map-loading-cell:nth-child(9)::after { animation-name: sectorCascade9; }

@keyframes sectorCascade1 {
    0%, 2%, 100% { opacity: 0; }
    5%, 90% { opacity: 1; }
    93% { opacity: 0; }
}

@keyframes sectorCascade6 {
    0%, 7%, 100% { opacity: 0; }
    10%, 86% { opacity: 1; }
    89% { opacity: 0; }
}

@keyframes sectorCascade7 {
    0%, 12%, 100% { opacity: 0; }
    15%, 82% { opacity: 1; }
    85% { opacity: 0; }
}

@keyframes sectorCascade2 {
    0%, 17%, 100% { opacity: 0; }
    20%, 78% { opacity: 1; }
    81% { opacity: 0; }
}

@keyframes sectorCascade9 {
    0%, 22%, 100% { opacity: 0; }
    25%, 74% { opacity: 1; }
    77% { opacity: 0; }
}

@keyframes sectorCascade4 {
    0%, 27%, 100% { opacity: 0; }
    30%, 70% { opacity: 1; }
    73% { opacity: 0; }
}

@keyframes sectorCascade5 {
    0%, 32%, 100% { opacity: 0; }
    35%, 66% { opacity: 1; }
    69% { opacity: 0; }
}

@keyframes sectorCascade3 {
    0%, 37%, 100% { opacity: 0; }
    40%, 62% { opacity: 1; }
    65% { opacity: 0; }
}

@keyframes sectorCascade8 {
    0%, 42%, 100% { opacity: 0; }
    45%, 58% { opacity: 1; }
    61% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .map-loading-cell::after {
        animation: none;
        opacity: 0;
        will-change: auto;
    }
}

.map-loading-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.map-loading-brand {
    font-family: "Special Gothic Expanded One", sans-serif;
    font-style: italic;
    font-size: 1.3rem;
    letter-spacing: -1px;
    color: #1a1a1a;
}

.map-loading-text {
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    font-weight: 400;
    color: #9ca3af;
    letter-spacing: 0.3px;
}

.map-loading-recovery {
    width: min(320px, calc(100vw - 40px));
    color: #4b5563;
    font-family: 'Roboto', sans-serif;
    font-size: 13px;
    line-height: 1.45;
    text-align: center;
}

.map-loading-recovery[hidden] {
    display: none;
}

.map-loading-recovery p {
    margin: 0;
}

.map-loading-overlay.failed .map-loading-text {
    color: #b91c1c;
}

@media (max-width: 480px) {
    .map-loading-overlay {
        gap: 20px;
    }

    .map-loading-grid {
        width: 60px;
        height: 60px;
        gap: 3px;
    }

    .map-loading-brand {
        font-size: 1.1rem;
    }

    .map-loading-text {
        font-size: 12px;
    }
}
