/* PRELOADER */

.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: #050505;
    z-index: 10000;
    transition: opacity 1.2s ease;
    pointer-events: none;
    opacity: 0;
    overflow: hidden;
    /* Свой GPU слой — не едет при compositing stack-card */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    isolation: isolate;
}

.preloader.visible {
    opacity: 1;
    pointer-events: auto;
}

.preloader.hidden {
    opacity: 0;
    pointer-events: none;
}

.preloader-flash {
    position: absolute;
    left: var(--flash-x, 50vw);
    top: var(--flash-y, 50vh);
    z-index: 0;
    width: clamp(120px, 18vw, 320px);
    height: auto;
    pointer-events: none;
    user-select: none;
    opacity: 0;
    mix-blend-mode: difference;
    filter: invert(1) contrast(1.45) saturate(1.4) hue-rotate(var(--flash-hue, 0deg));
    transform:
        translate3d(-50%, -50%, 0)
        rotate(var(--flash-rotate, 0deg))
        scale(var(--flash-scale, 1));
}

.preloader-flash.is-visible {
    animation: preloaderFlash 0.14s steps(2, end) both;
}

@keyframes preloaderFlash {
    0% { opacity: 0; }
    30%, 78% { opacity: 0.72; }
    100% { opacity: 0; }
}

/* CAMERA FRAME */
.cam-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 45vw;
    height: 60vh;
    min-width: 320px;
    min-height: 300px;
}

/* CORNERS */
.corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: rgba(10, 0, 255, 0.85);
    border-style: solid;
    pointer-events: none;
    animation: cornerPulse 2.8s ease-in-out infinite;
}

.corner--tl { top: 0;    left: 0;  border-width: 2px 0 0 2px; }
.corner--tr { top: 0;    right: 0; border-width: 2px 2px 0 0; }
.corner--bl { bottom: 0; left: 0;  border-width: 0 0 2px 2px; }
.corner--br { bottom: 0; right: 0; border-width: 0 2px 2px 0; }

.corner::after {
    content: '';
    position: absolute;
    width: 5px;
    height: 5px;
    background: rgba(10, 0, 255, 1);
    box-shadow: 0 0 10px rgba(10, 0, 255, 1), 0 0 20px rgba(10, 0, 255, 0.6);
}
.corner--tl::after { top: -1px;    left: -1px;  }
.corner--tr::after { top: -1px;    right: -1px; }
.corner--bl::after { bottom: -1px; left: -1px;  }
.corner--br::after { bottom: -1px; right: -1px; }

@keyframes cornerPulse {
    0%, 100% { opacity: 0.55; }
    50%       { opacity: 1;   }
}

/* LABEL ABOVE - top left outside frame */
.cam-label-top {
    position: absolute;
    top: -2em;
    left: 0;
    font-family: 'Terminus', 'Courier New', monospace;
    font-size: clamp(0.65rem, 1.1vw, 0.85rem);
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
    pointer-events: none;
    white-space: nowrap;
}

/* LABEL BELOW - bottom RIGHT outside frame */
.cam-label-bottom {
    position: absolute;
    bottom: -2em;
    right: 0;
    font-family: 'Terminus', 'Courier New', monospace;
    font-size: clamp(0.65rem, 1.1vw, 0.85rem);
    font-weight: 400;
    letter-spacing: 0.12em;
    color: rgba(186, 254, 0, 0.82);
    pointer-events: none;
    white-space: nowrap;
    display: flex;
    align-items: baseline;
}

.cam-label-dots {
    display: inline-block;
    width: 1.8em;
    overflow: hidden;
    animation: dotsGrow 1.2s steps(4, end) infinite;
}

@keyframes dotsGrow {
    0%   { width: 0; }
    25%  { width: 0.5em; }
    50%  { width: 1em; }
    75%  { width: 1.5em; }
    100% { width: 0; }
}

/* FPS - top left inside frame, 2x size */
.cam-fps {
    position: absolute;
    top: 10px;
    left: 10px;
    font-family: 'Terminus', 'Courier New', monospace;
    font-size: clamp(1.4rem, 2.8vw, 2.2rem);
    font-weight: 700;
    font-style: italic;
    display: flex;
    align-items: baseline;
    gap: 3px;
    line-height: 1;
    pointer-events: none;
}

.fps-current {
    color: #ffffff;
    text-shadow:
        0 0 8px rgba(10, 0, 255, 0.9),
        0 0 20px rgba(10, 0, 255, 0.6),
        0 0 40px rgba(10, 0, 255, 0.4);
    display: inline-block;
    min-width: 2ch;
}

.fps-slash {
    color: #2a2a2a;
    font-size: 0.65em;
}

.fps-max {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.75em;
}

.fps-label {
    color: #3a3a3a;
    font-size: 0.6em;
    font-style: normal;
    font-weight: 400;
    margin-left: 2px;
}

/* VERTICAL PROGRESS - bottom right inside frame */
.cam-progress-wrap {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 2px;
    height: calc(100% - 80px);
    pointer-events: none;
    overflow: visible;
}

.cam-progress-track {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.06);
}

.cam-progress-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top,
        rgba(10, 0, 120, 1) 0%,
        rgba(10, 0, 255, 0.9) 50%,
        rgba(10, 0, 255, 0.6) 100%);
    transition: height 0.1s linear;
    box-shadow:
        0 0 6px rgba(10, 0, 255, 0.9),
        0 0 16px rgba(10, 0, 255, 0.4);
}

.cam-progress-fill::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -4px;
    width: 10px;
    height: 2px;
    background: #0a00ff;
    box-shadow:
        0 0 8px rgba(10, 0, 255, 1),
        0 0 18px rgba(10, 0, 255, 0.8);
}

.cam-percent {
    position: absolute;
    bottom: 10px;
    right: 18px;
    font-family: 'Terminus', 'Courier New', monospace;
    font-size: 0.55rem;
    color: rgba(186, 254, 0, 0.78);
    text-shadow: 0 0 6px rgba(186, 254, 0, 0.38);
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    letter-spacing: 0.08em;
    pointer-events: none;
    white-space: nowrap;
}

/* ASCII center */
.cam-ascii-center {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    overflow: hidden;
}

#ascii-canvas {
    position: relative;
    z-index: 1;
    white-space: pre;
    line-height: 7px;
    font-size: 11px;
    font-family: 'Courier New', Courier, monospace;
    color: #bafe00;
    text-shadow:
        0 0 16px rgba(255, 255, 255, 0.25),
        0 0 34px rgba(255, 255, 255, 0.16),
        0 0 6px rgba(186, 254, 0, 0.82),
        0 0 18px rgba(186, 254, 0, 0.36);
    user-select: none;
    margin: 0;
    display: block;
    overflow: visible;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .cam-frame {
        width: min(82vw, 320px);
        height: 52vh;
        min-width: 0;
    }
    .corner { width: 20px; height: 20px; }
    .cam-fps { font-size: clamp(1.1rem, 4vw, 1.6rem); }
    .preloader-flash {
        width: clamp(90px, 32vw, 180px);
        mix-blend-mode: normal;
        filter: invert(1) contrast(1.12) saturate(1.1);
    }
    #ascii-canvas { font-size: 7px; line-height: 5px; }
    .cam-label-top,
    .cam-label-bottom {
        font-size: 0.55rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 80vw;
    }
}
