/* =========================================================================
   Kiby ERP — Splash screen · Animated logo draw
   Pure CSS (runs in index.html before Angular boots — no framework/JS).
   The Kiby "K" draws itself (outline traced → gradient fill floods in) and an
   accent loader pulses below. Plays once; the loader/glow loop until the app
   hides it via `.fuse-splash-screen-hidden` on <body>
   (see app.component.ts::initializeSplashScreenHiding).
   ========================================================================= */

body fuse-splash-screen {
    --k-bg: #161616;
    --k-accent: #d35a2f;
    --k-accent-lo: #b8481f;
    --k-accent-hi: #f2a365;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    inset: 0;
    background-color: var(--k-bg);
    z-index: 999999;
    pointer-events: none;
    opacity: 1;
    visibility: visible;
    overflow: hidden;
    transition: opacity 500ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ambient accent glow --------------------------------------------------- */
body fuse-splash-screen::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 480px;
    height: 480px;
    transform: translate(-50%, -50%) scale(0.6);
    background: radial-gradient(
        circle,
        rgba(211, 90, 47, 0.32) 0%,
        rgba(211, 90, 47, 0.1) 34%,
        transparent 68%
    );
    opacity: 0;
    filter: blur(6px);
    animation: k-glow-in 900ms cubic-bezier(0.22, 1, 0.36, 1) 120ms forwards,
        k-glow-breathe 4.5s ease-in-out 1.9s infinite;
}

body fuse-splash-screen .k-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1;
}

/* Logo box -------------------------------------------------------------- */
body fuse-splash-screen .k-logo {
    position: relative;
    width: 150px;
    height: 144px;
    opacity: 0;
    transform: scale(0.9);
    animation: k-logo-fade 500ms ease 200ms forwards,
        k-pop 700ms cubic-bezier(0.34, 1.56, 0.64, 1) 1550ms forwards;
}

body fuse-splash-screen .k-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
    animation: k-float 5s ease-in-out 2.1s infinite;
}

/* Outline traced first (the "drawing" phase) ---------------------------- */
body fuse-splash-screen .k-line {
    fill: none;
    stroke: var(--k-accent-hi);
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
}
body fuse-splash-screen .k-stem-line {
    animation: k-draw 600ms cubic-bezier(0.65, 0, 0.35, 1) 300ms forwards,
        k-line-out 300ms ease 950ms forwards;
}
body fuse-splash-screen .k-chev-line {
    animation: k-draw 720ms cubic-bezier(0.65, 0, 0.35, 1) 680ms forwards,
        k-line-out 320ms ease 1360ms forwards;
}

/* Gradient fill floods in after the trace ------------------------------- */
body fuse-splash-screen .k-fill {
    opacity: 0;
}
body fuse-splash-screen .k-stem-fill {
    animation: k-fill-in 450ms ease 820ms forwards;
}
body fuse-splash-screen .k-chev-fill {
    animation: k-fill-in 450ms ease 1220ms forwards;
}

/* Loader: glowing accent comet on a subtle track ------------------------ */
body fuse-splash-screen .k-loader {
    position: relative;
    margin-top: 34px;
    width: 150px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
    opacity: 0;
    animation: k-fade-in 600ms ease 1350ms forwards;
}
body fuse-splash-screen .k-loader span {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 45%;
    border-radius: inherit;
    background: linear-gradient(
        90deg,
        transparent,
        var(--k-accent-hi) 35%,
        var(--k-accent) 55%,
        transparent
    );
    box-shadow: 0 0 10px 1px rgba(211, 90, 47, 0.75);
    animation: k-loader-slide 1.25s cubic-bezier(0.65, 0, 0.35, 1) 1450ms infinite;
}

/* Keyframes ------------------------------------------------------------- */
@keyframes k-draw {
    to {
        stroke-dashoffset: 0;
    }
}
@keyframes k-line-out {
    to {
        opacity: 0;
    }
}
@keyframes k-fill-in {
    to {
        opacity: 1;
    }
}
@keyframes k-fade-in {
    to {
        opacity: 1;
    }
}
@keyframes k-loader-slide {
    0% {
        left: -45%;
        width: 45%;
    }
    50% {
        width: 55%;
    }
    100% {
        left: 100%;
        width: 45%;
    }
}
@keyframes k-logo-fade {
    to {
        opacity: 1;
    }
}
@keyframes k-pop {
    0% {
        transform: scale(0.9);
    }
    55% {
        transform: scale(1.04);
    }
    100% {
        transform: scale(1);
    }
}
@keyframes k-float {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}
@keyframes k-glow-in {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.6);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}
@keyframes k-glow-breathe {
    0%,
    100% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.08);
    }
}

/* Reduced motion: show finished logo, no trace ------------------------- */
@media (prefers-reduced-motion: reduce) {
    body fuse-splash-screen::before,
    body fuse-splash-screen .k-logo,
    body fuse-splash-screen .k-svg {
        animation: none;
        opacity: 1;
        transform: none;
    }
    body fuse-splash-screen .k-fill {
        animation: none;
        opacity: 1;
    }
    body fuse-splash-screen .k-line {
        display: none;
    }
    body fuse-splash-screen .k-loader {
        animation: none;
        opacity: 1;
    }
    body fuse-splash-screen .k-loader span {
        animation-delay: 0s;
    }
}

/* Hide / show ----------------------------------------------------------- */
body:not(.fuse-splash-screen-hidden) {
    overflow: hidden;
}

body.fuse-splash-screen-hidden fuse-splash-screen {
    visibility: hidden;
    opacity: 0;
}
