/* =======================================================
   Loading screen — Dragon Scale cosmic aesthetic
   Global (unscoped) — applies to both the static pre-Blazor
   loading div in index.html and the LoadingExperience component.
   Tokens resolved from brand.css / app.css which load before this.
   ======================================================= */

/* ---- Stage ---- */

.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: radial-gradient(
        circle at 50% 40%,
        color-mix(in srgb, var(--d-surface, #1e1a38) 40%, transparent) 0%,
        var(--d-bg, #0c0a18) 100%
    );
    position: relative;
    overflow: hidden;
}

/* Ambient nebula blobs */
.loading-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 55% 38% at 18% 28%, color-mix(in srgb, var(--d-primary, #5b3cc4) 9%, transparent) 0%, transparent 70%),
        radial-gradient(ellipse 45% 32% at 82% 68%, color-mix(in srgb, var(--d-teal, #4ed7c8) 7%, transparent) 0%, transparent 70%),
        radial-gradient(ellipse 38% 28% at 62% 18%, color-mix(in srgb, var(--d-gold, #f6c453) 5%, transparent) 0%, transparent 70%);
    animation: nebula-drift 14s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes nebula-drift {
    from { opacity: 0.5; transform: scale(1)    translateY(0);    }
    to   { opacity: 1;   transform: scale(1.10) translateY(-14px); }
}

/* ---- Floating spark particles ---- */

.loading-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0;
    animation: particle-drift linear infinite;
}

.p1 { left: 12%; top: 78%; width: 3px; height: 3px; background: var(--d-teal, #4ed7c8);    animation-duration: 7s;   animation-delay: 0s;   }
.p2 { left: 83%; top: 70%; width: 4px; height: 4px; background: var(--d-gold, #f6c453);    animation-duration: 5.5s; animation-delay: 1.2s; }
.p3 { left: 53%; top: 86%; width: 2px; height: 2px; background: var(--d-teal, #4ed7c8);    animation-duration: 8s;   animation-delay: 2.8s; }
.p4 { left: 27%; top: 62%; width: 3px; height: 3px; background: var(--d-primary, #5b3cc4); animation-duration: 6s;   animation-delay: 0.7s; }
.p5 { left: 68%; top: 80%; width: 2px; height: 2px; background: var(--d-gold, #f6c453);    animation-duration: 9s;   animation-delay: 3.5s; }
.p6 { left: 42%; top: 74%; width: 4px; height: 4px; background: var(--d-primary, #5b3cc4); animation-duration: 6.5s; animation-delay: 1.9s; }

@keyframes particle-drift {
    0%   { transform: translateY(0)     scale(1);    opacity: 0;   }
    10%  {                                            opacity: 0.9; }
    80%  {                                            opacity: 0.4; }
    100% { transform: translateY(-90px) scale(0.4);  opacity: 0;   }
}

/* ---- Content block (entrance animation) ---- */

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem;
    position: relative;
    z-index: 1;
    animation: content-enter 0.7s ease-out both;
}

@keyframes content-enter {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0);    }
}

/* ---- Logo + orbital rings ---- */

.loading-orb {
    position: relative;
    width: 260px;
    height: 260px;
}

.load-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid;
    animation: ring-spin var(--ring-dur, 8s) linear infinite;
    animation-direction: var(--ring-dir, normal);
}

/* Outer ring — teal glow */
.load-ring-1 {
    inset: 0;
    border-color: color-mix(in srgb, var(--d-teal, #4ed7c8) 48%, transparent);
    box-shadow: 0 0 12px color-mix(in srgb, var(--d-teal, #4ed7c8) 18%, transparent);
    --ring-dur: 7s;
}

/* Middle ring — gold, counter-clockwise */
.load-ring-2 {
    inset: 20px;
    border-color: color-mix(in srgb, var(--d-gold, #f6c453) 32%, transparent);
    box-shadow: 0 0 8px color-mix(in srgb, var(--d-gold, #f6c453) 12%, transparent);
    --ring-dur: 13s;
    --ring-dir: reverse;
}

/* Inner ring — primary, dashed orbital path */
.load-ring-3 {
    inset: 44px;
    border-color: color-mix(in srgb, var(--d-primary, #5b3cc4) 22%, transparent);
    border-style: dashed;
    --ring-dur: 22s;
}

@keyframes ring-spin {
    from { transform: rotate(0deg);   }
    to   { transform: rotate(360deg); }
}

/* Logo sits at center, breathes gently */
.loading-logo {
    position: absolute;
    inset: 60px;
    width: 140px;
    height: 140px;
    object-fit: contain;
    border-radius: 24px;
    z-index: 1;
    animation: logo-breathe 3.5s ease-in-out infinite;
}

@keyframes logo-breathe {
    0%, 100% {
        filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.45));
        transform: scale(1);
    }
    50% {
        filter:
            drop-shadow(0 8px 36px var(--d-glow-main, rgba(91, 60, 196, 0.25)))
            drop-shadow(0 0 18px var(--d-glow-teal, rgba(78, 215, 200, 0.30)));
        transform: scale(1.045);
    }
}

/* ---- Title ---- */

.loading-title {
    font-family: 'Cinzel', serif;
    font-size: 2.25rem;
    font-weight: 600;
    color: white;
    margin: 0;
    letter-spacing: 0.15em;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
}

/* ---- Pulsing dots ---- */

.loading-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 0.25rem;
}

.loading-dots {
    display: flex;
    align-items: center;
    gap: 7px;
}

.loading-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(1) {
    background-color: var(--d-teal, #4ed7c8);
}

.loading-dot:nth-child(2) {
    background-color: color-mix(in srgb, var(--d-teal, #4ed7c8) 55%, var(--d-gold, #f6c453) 45%);
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    background-color: var(--d-gold, #f6c453);
    animation-delay: 0.4s;
}

@keyframes dot-pulse {
    0%, 80%, 100% { transform: scale(0.55); opacity: 0.35; }
    40%            { transform: scale(1);    opacity: 1;    }
}

.loading-message {
    font-size: 0.95rem;
    color: color-mix(in srgb, var(--m-text-2, #b9b4e6) 80%, transparent);
    margin: 0;
    min-height: 1.5em;
    text-align: center;
    letter-spacing: 0.05em;
}

/* ---- Constellation SVG ---- */

.loading-constellation {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    animation: constellation-fade 2s ease-out 0.5s forwards;
}

@keyframes constellation-fade {
    to { opacity: 1; }
}

.star-node {
    fill: color-mix(in srgb, var(--d-teal, #4ed7c8) 60%, transparent);
    animation: star-twinkle 3s ease-in-out infinite;
}

.sn-1 { animation-delay: 0s; }
.sn-2 { animation-delay: 0.8s; }
.sn-3 { animation-delay: 1.4s; }
.sn-4 { animation-delay: 0.3s; }
.sn-5 { animation-delay: 2.1s; }
.sn-6 { animation-delay: 1.7s; }
.sn-7 { animation-delay: 0.5s; }
.sn-8 { animation-delay: 2.6s; }

@keyframes star-twinkle {
    0%, 100% { opacity: 0.3; r: 1.5; }
    50% { opacity: 1; r: 2.5; }
}

.star-line {
    stroke: color-mix(in srgb, var(--d-teal, #4ed7c8) 15%, transparent);
    stroke-width: 0.5;
    stroke-dasharray: 4 6;
    animation: line-draw 4s ease-out forwards;
    stroke-dashoffset: 200;
}

.sl-1 { animation-delay: 0.8s; }
.sl-2 { animation-delay: 1.0s; }
.sl-3 { animation-delay: 1.2s; }
.sl-4 { animation-delay: 1.5s; }
.sl-5 { animation-delay: 1.7s; }
.sl-6 { animation-delay: 1.9s; }
.sl-7 { animation-delay: 2.1s; }

@keyframes line-draw {
    to { stroke-dashoffset: 0; }
}

/* ---- Twinkling micro-stars ---- */

.twinkle-field {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.twinkle {
    position: absolute;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: white;
    opacity: 0;
    animation: twinkle-blink 2.5s ease-in-out infinite;
}

.tw-1  { left: 8%;  top: 12%; animation-delay: 0s; }
.tw-2  { left: 92%; top: 8%;  animation-delay: 0.7s; }
.tw-3  { left: 22%; top: 35%; animation-delay: 1.3s; }
.tw-4  { left: 78%; top: 42%; animation-delay: 0.4s; }
.tw-5  { left: 45%; top: 15%; animation-delay: 2.0s; }
.tw-6  { left: 65%; top: 88%; animation-delay: 1.1s; }
.tw-7  { left: 15%; top: 72%; animation-delay: 1.8s; }
.tw-8  { left: 88%; top: 65%; animation-delay: 0.2s; }
.tw-9  { left: 35%; top: 92%; animation-delay: 2.3s; }
.tw-10 { left: 55%; top: 5%;  animation-delay: 0.9s; }
.tw-11 { left: 5%;  top: 55%; animation-delay: 1.5s; }
.tw-12 { left: 72%; top: 28%; animation-delay: 2.7s; }

@keyframes twinkle-blink {
    0%, 100% { opacity: 0; transform: scale(0.5); }
    50% { opacity: 0.8; transform: scale(1.2); }
}

/* ---- Extra particles (p7, p8) ---- */

.p7 { left: 38%; top: 90%; width: 2px; height: 2px; background: var(--d-teal, #4ed7c8);    animation-duration: 7.5s; animation-delay: 4.2s; }
.p8 { left: 75%; top: 65%; width: 3px; height: 3px; background: var(--d-gold, #f6c453);    animation-duration: 5s;   animation-delay: 2.0s; }

/* ---- Orbiting dot ---- */

.orbit-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--d-teal, #4ed7c8);
    box-shadow: 0 0 8px var(--d-teal, #4ed7c8), 0 0 16px color-mix(in srgb, var(--d-teal, #4ed7c8) 40%, transparent);
    z-index: 2;
}

.orbit-dot-1 {
    top: 50%;
    left: 50%;
    margin-top: -3px;
    margin-left: -3px;
    animation: orbit-around 7s linear infinite;
}

@keyframes orbit-around {
    from { transform: rotate(0deg)   translateX(130px) rotate(0deg); }
    to   { transform: rotate(360deg) translateX(130px) rotate(-360deg); }
}

/* ---- Loading message fade transition ---- */

.loading-message {
    transition: opacity 0.4s ease;
}

/* ---- Shimmer progress bar ---- */

.loading-shimmer-track {
    width: 160px;
    height: 3px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--d-primary, #5b3cc4) 20%, transparent);
    overflow: hidden;
    margin-top: 0.5rem;
}

.loading-shimmer-fill {
    width: 40%;
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--d-teal, #4ed7c8), var(--d-gold, #f6c453), var(--d-primary, #5b3cc4));
    animation: shimmer-slide 2s ease-in-out infinite;
}

@keyframes shimmer-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
    .loading-screen::before { animation: none; }
    .particle               { animation: none; display: none; }
    .load-ring              { animation: none; }
    .loading-logo           { animation: none; filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.4)); }
    .loading-content        { animation: none; }
    .loading-dot            { animation: none; opacity: 1; transform: none; }
    .loading-constellation  { animation: none; opacity: 0.6; }
    .star-node              { animation: none; opacity: 0.5; }
    .star-line              { animation: none; stroke-dashoffset: 0; }
    .twinkle                { animation: none; display: none; }
    .orbit-dot              { animation: none; display: none; }
    .loading-shimmer-fill   { animation: none; transform: none; }
}

/* ---- Mobile ---- */

@media (max-width: 480px) {
    .loading-orb {
        width: 200px;
        height: 200px;
    }

    .loading-logo {
        inset: 46px;
        width: 108px;
        height: 108px;
    }

    .load-ring-2 { inset: 16px; }
    .load-ring-3 { inset: 34px; }

    .loading-title {
        font-size: 1.75rem;
    }

    .orbit-dot-1 {
        animation-name: orbit-around-mobile;
    }

    .loading-shimmer-track {
        width: 120px;
    }
}

@keyframes orbit-around-mobile {
    from { transform: rotate(0deg)   translateX(100px) rotate(0deg); }
    to   { transform: rotate(360deg) translateX(100px) rotate(-360deg); }
}

/* ---- Light mode ---- */

html[data-theme="light"] .loading-screen {
    background: radial-gradient(
        circle at 50% 40%,
        color-mix(in srgb, var(--m-surface, #ece7ff) 60%, transparent) 0%,
        var(--m-bg, #f6f4ff) 100%
    );
}

html[data-theme="light"] .loading-title {
    color: var(--m-text, #2e1f66);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

html[data-theme="light"] .loading-dot:nth-child(1) { background-color: var(--m-primary, #5b3cc4); }
html[data-theme="light"] .loading-dot:nth-child(2) { background-color: color-mix(in srgb, var(--m-primary, #5b3cc4) 55%, var(--m-accent, #f6c453) 45%); }
html[data-theme="light"] .loading-dot:nth-child(3) { background-color: var(--m-accent, #f6c453); }

html[data-theme="light"] .loading-message {
    color: var(--m-text-2, #5c4fa3);
}

html[data-theme="light"] .star-node {
    fill: color-mix(in srgb, var(--m-primary, #5b3cc4) 50%, transparent);
}

html[data-theme="light"] .star-line {
    stroke: color-mix(in srgb, var(--m-primary, #5b3cc4) 12%, transparent);
}

html[data-theme="light"] .twinkle {
    background: var(--m-primary, #5b3cc4);
}

html[data-theme="light"] .orbit-dot {
    background: var(--m-primary, #5b3cc4);
    box-shadow: 0 0 8px var(--m-primary, #5b3cc4);
}

html[data-theme="light"] .loading-shimmer-track {
    background: color-mix(in srgb, var(--m-primary, #5b3cc4) 15%, transparent);
}

/* ---- Blazor error banner (pre-framework, styled here so it works before Blazor boots) ---- */

.blazor-error-banner {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, #1e1a38 0%, #2a1545 100%);
    border-top: 1px solid color-mix(in srgb, var(--m-error, #ff6b6b) 30%, transparent);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--m-text, #f8f7ff);
}

.blazor-error-inner {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.blazor-error-text {
    flex: 1;
    min-width: 200px;
}

.blazor-error-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.blazor-error-warn-icon {
    color: var(--m-error, #ff6b6b);
    font-size: 1.1rem;
}

.blazor-error-strong {
    font-size: 0.9rem;
    color: var(--m-error, #ff6b6b);
}

.blazor-error-desc {
    margin: 0;
    font-size: 0.8rem;
    color: #b9b4e6;
    line-height: 1.4;
}

.blazor-error-sri {
    display: none;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #b9b4e6;
}

.blazor-error-sri p {
    margin: 0;
}

.blazor-error-cache-label {
    color: #ffb84d;
}

.blazor-error-recovery {
    display: none;
    font-size: 0.75rem;
    color: #5edc91;
    margin: 0.25rem 0 0;
}

.blazor-error-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.blazor-error-reload-btn {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--m-error, #ff6b6b) 40%, transparent);
    background: color-mix(in srgb, var(--m-error, #ff6b6b) 10%, transparent);
    color: var(--m-error, #ff6b6b);
    cursor: pointer;
    transition: background 0.2s ease;
}

.blazor-error-reload-btn:hover {
    background: color-mix(in srgb, var(--m-error, #ff6b6b) 20%, transparent);
}

.blazor-error-clear-btn {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--m-primary, #5b3cc4) 50%, transparent);
    background: var(--m-primary, #5b3cc4);
    color: var(--m-on-primary, #f8f7ff);
    cursor: pointer;
    transition: background 0.2s ease;
}

.blazor-error-clear-btn:hover {
    background: color-mix(in srgb, var(--m-primary, #5b3cc4) 85%, #fff 15%);
}
