/* ============================================================
   World Loading Screen
   Full-screen boot sequence shown after login. Progress is fed by
   real load stages (terrain textures, vector chunks, weather, hub).
   ============================================================ */

/* Bis zum Start bleibt die 2D-Karte bzw. die 3D-Szene verborgen. Der
   Loader und die Landing Page liegen darüber; so blitzt beim App-Start
   zu keinem Zeitpunkt die Karte durch. */
body:not(.world-entered) #game-canvas,
body:not(.world-entered) .hud-layer {
    visibility: hidden !important;
}

#world-loader {
    position: fixed;
    inset: 0;
    z-index: 3200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
    background: #04050a;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Der Loader erscheint sofort. Nur die Karte im Inneren animiert ein – so
   bleibt der Bildschirm auch in gedrosselten Tabs sichtbar, die keine
   CSS-Transitions zeichnen. */
#world-loader.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

#world-loader.is-leaving {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.loader-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 16% 8%, rgba(112, 0, 255, 0.32) 0%, transparent 54%),
        radial-gradient(ellipse at 86% 84%, rgba(255, 0, 127, 0.24) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 46%, #0c0e19 0%, #05060c 72%);
}

.loader-aurora {
    position: absolute;
    width: 58vw;
    height: 58vw;
    max-width: 880px;
    max-height: 880px;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.5;
    pointer-events: none;
    will-change: transform;
}

.loader-aurora-a {
    top: -22%;
    left: -14%;
    background: radial-gradient(circle, rgba(0, 240, 255, 0.34), rgba(112, 0, 255, 0.16) 45%, transparent 70%);
    animation: loaderAuroraA 16s ease-in-out infinite alternate;
}

.loader-aurora-b {
    right: -18%;
    bottom: -26%;
    background: radial-gradient(circle, rgba(255, 0, 127, 0.32), rgba(112, 0, 255, 0.15) 48%, transparent 72%);
    animation: loaderAuroraB 19s ease-in-out infinite alternate;
}

@keyframes loaderAuroraA {
    0% { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(9%, 6%, 0) scale(1.16); }
}

@keyframes loaderAuroraB {
    0% { transform: translate3d(0, 0, 0) scale(1.08); }
    100% { transform: translate3d(-8%, -5%, 0) scale(1); }
}

.loader-grid-floor {
    position: absolute;
    left: -35%;
    right: -35%;
    bottom: -14%;
    height: 48%;
    background-image:
        linear-gradient(rgba(0, 240, 255, 0.14) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 240, 255, 0.11) 1px, transparent 1px);
    background-size: 64px 64px;
    transform: perspective(520px) rotateX(64deg);
    transform-origin: bottom center;
    -webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent 76%);
    mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent 76%);
    opacity: 0.45;
    pointer-events: none;
}

.loader-scanlines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0, rgba(255, 255, 255, 0.025) 1px, transparent 1px, transparent 3px);
    opacity: 0.35;
    pointer-events: none;
}

.loader-card {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(940px, 96vw);
    max-height: calc(100vh - 48px);
    padding: 34px 34px 28px;
    overflow: hidden;
    border-radius: 26px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: linear-gradient(158deg, rgba(20, 22, 38, 0.94), rgba(8, 9, 16, 0.97));
    box-shadow:
        0 40px 90px rgba(0, 0, 0, 0.72),
        0 0 60px rgba(255, 0, 127, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    animation: loaderCardIn 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.loader-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 12%;
    right: 12%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 0, 127, 0.8), rgba(0, 240, 255, 0.8), transparent);
    pointer-events: none;
}

@keyframes loaderCardIn {
    from { opacity: 0; transform: translateY(16px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.loader-head {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
}

.loader-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(0, 240, 255, 0.22);
    background: rgba(0, 240, 255, 0.06);
    color: #7fe9f5;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 1.6px;
}

.loader-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #19f7c8;
    box-shadow: 0 0 10px rgba(25, 247, 200, 0.9);
    animation: loaderLivePulse 1.8s ease-in-out infinite;
}

@keyframes loaderLivePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.78); }
}

.loader-title {
    margin: 14px 0 8px;
    font-size: clamp(1.75rem, 3.3vw, 2.45rem);
    font-weight: 900;
    letter-spacing: -0.5px;
    line-height: 1.08;
    background: linear-gradient(96deg, #ffffff 12%, #ffb3d9 58%, #93e9ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.loader-subtitle {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-muted, #94a3b8);
}

.loader-main {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.9fr);
    gap: 24px;
    margin-top: 28px;
    position: relative;
    z-index: 1;
    /* Der Mittelteil scrollt bei knappen Höhen, der Kopf bleibt stehen. */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 0, 127, 0.45) transparent;
}

.loader-progress {
    min-width: 0;
}

.loader-progress-top {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 10px;
}

.loader-progress-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: #cbd5e1;
}

.loader-progress-value {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 2.1rem;
    font-weight: 900;
    line-height: 1;
    color: #ffffff;
    text-shadow: 0 0 24px rgba(0, 240, 255, 0.35);
}

.loader-progress-value small {
    font-size: 0.9rem;
    color: var(--text-muted, #94a3b8);
    font-weight: 700;
}

.loader-track {
    position: relative;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

.loader-fill {
    position: relative;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ff007f 0%, #a100ff 48%, #00d2ff 100%);
    box-shadow: 0 0 18px rgba(255, 0, 127, 0.55);
    /* Kein Width-Transition: Der Balken soll den echten Fortschritt zeigen,
       auch wenn ein Tab keine Frames zeichnet. */
}

.loader-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.55) 46%, transparent 72%);
    background-size: 220% 100%;
    animation: loaderFillSheen 1.9s linear infinite;
}

@keyframes loaderFillSheen {
    from { background-position: 180% 0; }
    to { background-position: -80% 0; }
}

.loader-stages {
    list-style: none;
    margin: 20px 0 0;
    padding: 0;
    display: grid;
    gap: 7px;
}

.loader-stage {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.045);
    background: rgba(255, 255, 255, 0.018);
    color: #8b94a8;
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.loader-stage-icon {
    position: relative;
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(148, 163, 184, 0.5);
    transition: border-color 0.3s ease, background 0.3s ease;
}

.loader-stage.is-active {
    background: rgba(0, 240, 255, 0.055);
    border-color: rgba(0, 240, 255, 0.2);
    color: #e8f7ff;
}

.loader-stage.is-active .loader-stage-icon {
    border-color: transparent;
    background: transparent;
}

.loader-stage.is-active .loader-stage-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(0, 240, 255, 0.22);
    border-top-color: #00f0ff;
    animation: loaderSpin 0.8s linear infinite;
}

@keyframes loaderSpin {
    to { transform: rotate(360deg); }
}

.loader-stage.is-done {
    color: #b8c4d6;
    background: rgba(25, 247, 200, 0.035);
    border-color: rgba(25, 247, 200, 0.12);
}

.loader-stage.is-done .loader-stage-icon {
    border-color: rgba(25, 247, 200, 0.65);
    background: rgba(25, 247, 200, 0.14);
}

.loader-stage.is-done .loader-stage-icon::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.66rem;
    font-weight: 900;
    color: #19f7c8;
}

.loader-stage.is-skipped .loader-stage-icon {
    border-color: rgba(148, 163, 184, 0.35);
    background: rgba(148, 163, 184, 0.08);
}

.loader-stage.is-skipped .loader-stage-icon::after {
    content: '–';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #94a3b8;
}

.loader-stage-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loader-stage-state {
    flex: 0 0 auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.66rem;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #6f7a8f;
}

.loader-stage.is-active .loader-stage-state { color: #00f0ff; }
.loader-stage.is-done .loader-stage-state { color: #19f7c8; }

.loader-patches {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015));
}

.loader-patches-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 1.6px;
    color: #ffc2e1;
}

.loader-version {
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 0, 127, 0.3);
    background: rgba(255, 0, 127, 0.1);
    color: #ffd8ec;
    font-size: 0.64rem;
    letter-spacing: 0.4px;
    white-space: nowrap;
    max-width: 58%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loader-patch-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
    flex: 1 1 auto;
    align-content: start;
}

.loader-patch {
    position: relative;
    padding: 10px 11px 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.055);
    background: rgba(8, 10, 18, 0.55);
    overflow: hidden;
}

.loader-patch::before {
    content: '';
    position: absolute;
    left: 0;
    top: 9px;
    bottom: 9px;
    width: 2px;
    border-radius: 2px;
    background: linear-gradient(180deg, #ff007f, #00f0ff);
}

.loader-patch-title {
    overflow-wrap: anywhere;
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.35;
    color: #eef2f9;
}

.loader-patch-meta {
    margin-top: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.64rem;
    letter-spacing: 0.4px;
    color: #8792a6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loader-patch.is-latest {
    border-color: rgba(255, 0, 127, 0.18);
}

.loader-patch.is-milestone-major {
    border-color: rgba(255, 0, 127, 0.42);
}

.loader-patch.is-milestone-minor {
    border-color: rgba(0, 240, 255, 0.32);
}

.loader-patch-milestone {
    display: inline-flex;
    align-items: center;
    margin-top: 7px;
    padding: 2px 6px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    line-height: 1.4;
}

.loader-patch-milestone.is-major {
    border-color: rgba(255, 0, 127, 0.45);
    background: rgba(255, 0, 127, 0.14);
    color: #ffd6ea;
}

.loader-patch-milestone.is-minor {
    border-color: rgba(0, 240, 255, 0.35);
    background: rgba(0, 240, 255, 0.10);
    color: #c9f7ff;
}

.loader-patch-summary {
    margin-top: 7px;
    color: #9eacbf;
    font-size: 0.68rem;
    line-height: 1.45;
}

.loader-patch-highlights {
    display: grid;
    gap: 4px;
    margin: 7px 0 0;
    padding: 0;
    list-style: none;
}

.loader-patch-highlight {
    position: relative;
    padding-left: 11px;
    color: #c5d0df;
    font-size: 0.65rem;
    line-height: 1.4;
}

.loader-patch-highlight::before {
    content: '';
    position: absolute;
    left: 1px;
    top: 0.52em;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff007f, #00f0ff);
}

.loader-patch-skeleton {
    height: 58px;
    border-color: rgba(255, 255, 255, 0.04);
    background:
        linear-gradient(100deg, rgba(255, 255, 255, 0.03) 20%, rgba(255, 255, 255, 0.075) 40%, rgba(255, 255, 255, 0.03) 60%);
    background-size: 220% 100%;
    animation: loaderSkeleton 1.7s linear infinite;
}

@keyframes loaderSkeleton {
    from { background-position: 180% 0; }
    to { background-position: -80% 0; }
}

.loader-patch-empty {
    padding: 14px;
    border-style: dashed;
    color: #7c869a;
    font-size: 0.76rem;
    line-height: 1.4;
    text-align: center;
}

.loader-patches-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.62rem;
    letter-spacing: 0.8px;
    color: #5f6a7e;
    text-decoration: none;
    text-transform: uppercase;
}

.loader-patches-foot:hover {
    color: #8be9ff;
}

#world-loader.is-ready .loader-title {
    background: linear-gradient(96deg, #ffffff 8%, #b9ffe9 46%, #8be9ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#world-loader.is-ready .loader-progress-value {
    color: #b9ffe9;
    text-shadow: 0 0 26px rgba(25, 247, 200, 0.45);
}

@media (max-width: 860px) {
    .loader-card {
        padding: 26px 22px 22px;
    }

    .loader-main {
        grid-template-columns: minmax(0, 1fr);
        gap: 18px;
        margin-top: 22px;
    }

    .loader-patches {
        order: 2;
    }

}

@media (max-height: 720px) and (min-width: 861px) {
    .loader-card {
        padding: 24px 30px 20px;
    }

    .loader-main {
        margin-top: 20px;
    }

    .loader-stage {
        padding: 7px 11px;
    }

}

@media (prefers-reduced-motion: reduce) {
    .loader-aurora,
    .loader-live-dot,
    .loader-fill::after,
    .loader-patch-skeleton,
    .loader-card {
        animation: none !important;
    }

    .loader-fill,
    #world-loader,
    .loader-card {
        transition-duration: 0.01s !important;
    }
}
