/* ============================================
   BOOT ANIMATION - Terminal startup sequence
============================================ */

/* Boot Screen Overlay */
.boot-screen {
    position: fixed;
    inset: 0;
    background: #000;
    overflow: hidden;
    isolation: isolate;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease-out, visibility 0s linear 0s;
}

.boot-screen--hidden {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-out, visibility 0s linear 0.5s;
}

/* Terminal Container */
.boot-screen__terminal {
    width: 90%;
    max-width: 500px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 16px;
    line-height: 1.6;
    position: relative;
    z-index: 1;
    filter: contrast(1.06) brightness(1.02);
    animation: crtFlicker 9s infinite;
    will-change: opacity, transform, filter;
}

/* Terminal Lines */
.boot-screen__line {
    color: #33ff33;
    opacity: 0;
    margin-bottom: 8px;
    white-space: nowrap;
    text-shadow:
        0 0 4px rgba(51, 255, 51, 0.45),
        0 0 12px rgba(51, 255, 51, 0.22),
        0 0 28px rgba(51, 255, 51, 0.12);
}

.boot-screen__line::first-letter {
    color: rgba(51, 255, 51, 0.92);
    text-shadow:
        0 0 6px rgba(51, 255, 51, 0.55),
        0 0 18px rgba(51, 255, 51, 0.25);
}

.boot-screen__line--visible {
    opacity: 1;
}

.boot-screen__line--typing {
    position: relative;
}

.boot-screen__line--typed {
    position: relative;
}

/* Block cursor */
.boot-screen__line--typing::after,
.boot-screen__line--cursor::after {
    content: '';
    display: inline-block;
    width: 0.62em;
    height: 1.05em;
    margin-left: 2px;
    background: rgba(51, 255, 51, 0.92);
    box-shadow:
        0 0 6px rgba(51, 255, 51, 0.5),
        0 0 18px rgba(51, 255, 51, 0.22);
    transform: translateY(2px);
}

.boot-screen__line--cursor {
    position: relative;
}

.boot-screen__line--cursor::after {
    animation: blockBlink 1.05s step-end infinite;
}

@keyframes blockBlink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}

@keyframes crtFlicker {
    0% {
        opacity: 1;
        transform: translate3d(0, 0, 0);
        filter: contrast(1.06) brightness(1.02);
    }
    7% {
        opacity: 0.98;
    }
    8% {
        opacity: 1;
    }
    15% {
        opacity: 0.985;
        transform: translate3d(0.2px, 0, 0);
        filter: contrast(1.08) brightness(1.04);
    }
    16% {
        opacity: 1;
        transform: translate3d(0, 0, 0);
        filter: contrast(1.06) brightness(1.02);
    }
    30% {
        opacity: 0.975;
        transform: translate3d(-0.2px, 0.15px, 0);
    }
    31% {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0);
        filter: contrast(1.06) brightness(1.02);
    }
}

/* Progress Bar */
.boot-screen__progress {
    margin-top: 24px;
    height: 20px;
    background: #0b0f0b;
    border: 1px solid rgba(51, 255, 51, 0.85);
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow:
        0 0 0 1px rgba(51, 255, 51, 0.08),
        0 0 18px rgba(51, 255, 51, 0.08);
}

.boot-screen__progress--visible {
    opacity: 1;
}

.boot-screen__progress-bar {
    height: 100%;
    width: 0;
    position: relative;
    background:
        repeating-linear-gradient(
            90deg,
            rgba(0, 0, 0, 0.32) 0px,
            rgba(0, 0, 0, 0.32) 1px,
            rgba(0, 0, 0, 0) 1px,
            rgba(0, 0, 0, 0) 8px
        ),
        linear-gradient(
            to bottom,
            rgba(51, 255, 51, 0.95) 0%,
            rgba(51, 255, 51, 0.85) 100%
        );
    box-shadow:
        0 0 10px rgba(51, 255, 51, 0.25),
        0 0 22px rgba(51, 255, 51, 0.12);
    transition: width 1s ease-in-out;
}

.boot-screen__progress-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.18) 45%,
        rgba(255, 255, 255, 0.22) 55%,
        transparent 100%
    );
    transform: translateX(-140%) skewX(-20deg);
}

.boot-screen__progress-bar--filling {
    width: 100%;
}

.boot-screen__progress-bar--filling::after {
    opacity: 1;
    animation: progressSheen 900ms linear infinite;
}

@keyframes progressSheen {
    from {
        transform: translateX(-140%) skewX(-20deg);
    }
    to {
        transform: translateX(240%) skewX(-20deg);
    }
}

/* Desktop & Menu Bar Hidden State */
.desktop--hidden,
.menu-bar--hidden {
    opacity: 0;
    animation: none !important;
}

.desktop--revealing,
.menu-bar--revealing {
    animation: desktopReveal 0.4s ease-out forwards;
}

@keyframes desktopReveal {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Animated Cursor */
.boot-cursor {
    position: fixed;
    width: 16px;
    height: 20px;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 20"><polygon fill="%23000" stroke="%23fff" stroke-width="1" points="0,0 0,16 4,12 7,19 9,18 6,11 12,11"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -50%);
}

.boot-cursor--visible {
    opacity: 1;
}

.boot-cursor--moving {
    transition: left 0.8s cubic-bezier(0.4, 0, 0.2, 1),
                top 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.boot-cursor--clicking {
    animation: cursorClick 0.15s ease-in-out;
}

@keyframes cursorClick {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(0.85);
    }
}

.boot-cursor--hidden {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

/* CRT overlays (scanlines + noise/vignette) */
.boot-screen::before {
    content: '';
    position: absolute;
    inset: -2px;
    z-index: 2;
    background-image:
        radial-gradient(
            ellipse at center,
            rgba(51, 255, 51, 0.07) 0%,
            rgba(0, 0, 0, 0) 55%,
            rgba(0, 0, 0, 0.85) 100%
        ),
        url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="3" stitchTiles="stitch"/></filter><rect width="240" height="240" filter="url(%23n)" opacity="0.35"/></svg>');
    background-size: cover, 240px 240px;
    background-repeat: no-repeat, repeat;
    opacity: 0.18;
    pointer-events: none;
    animation: crtNoise 900ms steps(2, end) infinite;
}

.boot-screen::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 3;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(0, 0, 0, 0) 0px,
            rgba(0, 0, 0, 0) 1px,
            rgba(0, 0, 0, 0.14) 2px,
            rgba(0, 0, 0, 0.14) 3px
        ),
        linear-gradient(
            to bottom,
            transparent 0%,
            rgba(51, 255, 51, 0.06) 50%,
            transparent 100%
        );
    background-size: 100% 4px, 100% 140px;
    background-position: 0 0, 0 -140px;
    pointer-events: none;
    opacity: 0.25;
    animation: scanlineScroll 8s linear infinite;
}

@keyframes crtNoise {
    0% {
        transform: translate3d(0, 0, 0);
        background-position: 0 0, 0 0;
    }
    10% {
        transform: translate3d(-0.5%, 0.5%, 0);
        background-position: 0 0, 32px -12px;
    }
    20% {
        transform: translate3d(0.5%, -0.5%, 0);
        background-position: 0 0, -12px 24px;
    }
    30% {
        transform: translate3d(-0.25%, -0.25%, 0);
        background-position: 0 0, 18px -30px;
    }
    40% {
        transform: translate3d(0.25%, 0.25%, 0);
        background-position: 0 0, -28px 10px;
    }
    100% {
        transform: translate3d(0, 0, 0);
        background-position: 0 0, 0 0;
    }
}

@keyframes scanlineScroll {
    0% {
        background-position: 0 0, 0 -140px;
    }
    100% {
        background-position: 0 4px, 0 calc(100% + 140px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .boot-screen__terminal {
        animation: none;
    }

    .boot-screen::before,
    .boot-screen::after {
        animation: none;
    }

    .boot-screen__line--cursor::after {
        animation: none;
        opacity: 1;
    }

    .boot-screen__progress-bar--filling::after {
        animation: none;
        opacity: 0;
    }

    .boot-cursor--moving {
        transition: none;
    }

    .boot-cursor--clicking {
        animation: none;
    }

    .desktop--revealing,
    .menu-bar--revealing {
        animation: none;
        opacity: 1;
    }
}
