/* ============================================================================
   CINEMATIC INTRO SEQUENCE
   Flow: fade from black -> intro.mp4 (full-bleed) -> freeze last frame
         -> HTML QR-scan match -> processing / security screen -> power-on reveal
   ========================================================================== */

:root {
    --intro-red:    #d24b3d;
    --intro-red-2:  rgba(210, 75, 61, 0.55);
    --intro-silver: #b9bfca;
    --intro-ink:    #050609;
}

body.intro-active { overflow: hidden; }

/* ---------- Overlay shell ---------- */
.intro-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
    opacity: 1;
    perspective: 1400px;
}

/* Power-on reveal — bloom out and dissolve like a system booting */
.intro-overlay.intro-reveal {
    animation: introReveal 1.25s cubic-bezier(0.83, 0, 0.17, 1) forwards;
}
@keyframes introReveal {
    0%   { opacity: 1; transform: scale(1);    filter: brightness(1) blur(0); clip-path: inset(0 0 0 0); }
    30%  { opacity: 1; transform: scale(1.015); filter: brightness(2.4) blur(2px); }
    62%  { clip-path: inset(0 0 0 0); }
    100% { opacity: 0; transform: scale(1.12);  filter: brightness(3) blur(20px); clip-path: inset(50% 0 50% 0); }
}
.intro-overlay.intro-hidden { display: none; }

/* ---------- Film treatment: letterbox, vignette, grain, scanlines ---------- */
.intro-cine { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.intro-cine::before,
.intro-cine::after {
    content: "";
    position: absolute;
    left: 0; right: 0;
    height: 7vh;
    background: #000;
    z-index: 8;
    transition: height 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
.intro-cine::before { top: 0; }
.intro-cine::after  { bottom: 0; }
.intro-overlay.intro-reveal .intro-cine::before,
.intro-overlay.intro-reveal .intro-cine::after { height: 0; }

.intro-vignette {
    position: absolute; inset: 0; z-index: 7; pointer-events: none;
    background: radial-gradient(120% 100% at 50% 50%, transparent 38%, rgba(0,0,0,0.6) 100%);
    mix-blend-mode: multiply;
}
.intro-grain {
    position: absolute; inset: -50%; z-index: 7; pointer-events: none;
    opacity: 0.06;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    animation: grainShift 0.55s steps(3) infinite;
}
@keyframes grainShift {
    0%   { transform: translate(0, 0); }
    33%  { transform: translate(-3%, 2%); }
    66%  { transform: translate(2%, -3%); }
    100% { transform: translate(0, 0); }
}
.intro-scanlines {
    position: absolute; inset: 0; z-index: 7; pointer-events: none;
    opacity: 0.22;
    background: repeating-linear-gradient(to bottom,
        rgba(255,255,255,0.03) 0px, rgba(255,255,255,0.03) 1px,
        transparent 2px, transparent 3px);
}

/* ---------- Video stage (fades in from black) ---------- */
.intro-stage {
    position: absolute; inset: 0; z-index: 2;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity 1.1s ease, filter 0.6s ease, transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
    transform: scale(1.04);
}
.intro-stage.is-live { opacity: 1; transform: scale(1); }
/* Freeze-frame hold: keep the last frame perfectly visible, just settle scale */
.intro-stage.is-frozen { filter: none; transform: scale(1.01); }
/* Once the scan page is up, the video is GONE — it fades out entirely and the
   standalone QR scan page takes over. */
.intro-stage.is-dim { opacity: 0; filter: brightness(0.6) blur(6px); transform: scale(1.08); }

.intro-video {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}

/* Fallback poster if the video is missing/blocked */
.intro-fallback {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1.2rem; text-align: center;
    background:
        radial-gradient(60% 60% at 50% 45%, rgba(210,75,61,0.16), transparent 70%),
        radial-gradient(50% 50% at 50% 60%, rgba(80,90,110,0.16), transparent 70%);
    opacity: 0;
    transition: opacity 0.6s ease;
}
.intro-fallback.is-shown { opacity: 1; }
.intro-fallback .fallback-ring {
    width: clamp(120px, 22vw, 200px); height: clamp(120px, 22vw, 200px);
    border-radius: 50%;
    border: 2px solid rgba(210,75,61,0.35);
    box-shadow: 0 0 60px rgba(210,75,61,0.22), inset 0 0 40px rgba(120,130,150,0.15);
    display: flex; align-items: center; justify-content: center;
    animation: fallbackPulse 2.4s ease-in-out infinite;
}
.intro-fallback .fallback-ring svg { width: 46%; height: 46%; color: var(--intro-red); opacity: 0.9; }
.intro-fallback p {
    font-family: 'Space Mono', monospace;
    letter-spacing: 0.35em; text-transform: uppercase;
    font-size: clamp(0.6rem, 1.6vw, 0.8rem); color: rgba(185,191,202,0.7);
}
@keyframes fallbackPulse {
    0%,100% { transform: scale(1);   box-shadow: 0 0 50px rgba(210,75,61,0.2), inset 0 0 40px rgba(120,130,150,0.12); }
    50%     { transform: scale(1.05); box-shadow: 0 0 80px rgba(210,75,61,0.4), inset 0 0 60px rgba(120,130,150,0.22); }
}

/* ---------- Skip button ---------- */
.intro-skip {
    position: absolute; right: max(1.5rem, 3vw); bottom: calc(7vh + 1.2rem); z-index: 20;
    display: inline-flex; align-items: center; gap: 0.55rem;
    padding: 0.5rem 1.1rem;
    font-family: 'Space Mono', monospace; font-size: 0.68rem;
    letter-spacing: 0.28em; text-transform: uppercase;
    color: rgba(185,191,202,0.75);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(210,75,61,0.3);
    border-radius: 999px; backdrop-filter: blur(8px);
    cursor: pointer; opacity: 0; transform: translateY(8px);
    transition: opacity 0.5s ease, transform 0.5s ease, color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}
.intro-skip.is-shown { opacity: 1; transform: translateY(0); }
.intro-skip:hover { color: #fff; border-color: var(--intro-red); background: rgba(210,75,61,0.12); }
.intro-skip .skip-arrow { transition: transform 0.3s ease; }
.intro-skip:hover .skip-arrow { transform: translateX(3px); }

/* ==================== PROCESSING / SECURITY SCREEN ==================== */
.intro-processing {
    position: absolute; inset: 0; z-index: 10;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: clamp(1.4rem, 3.5vh, 2.4rem);
    opacity: 0; pointer-events: none;
    transition: opacity 0.7s ease;
    /* Standalone dark scan page (the video is gone by now). */
    background:
        radial-gradient(60% 60% at 50% 42%, rgba(210,75,61,0.12), transparent 66%),
        radial-gradient(130% 110% at 50% 50%, rgba(8,10,14,0.94), rgba(3,4,7,0.99) 100%);
}
.intro-processing.is-shown { opacity: 1; }

/* Scanner frame around a faux QR — the HTML recreation of the final frame */
.qr-frame {
    position: relative;
    width: clamp(200px, 44vw, 300px); height: clamp(200px, 44vw, 300px);
    display: flex; align-items: center; justify-content: center;
    border-radius: 14px;
    background: linear-gradient(150deg, rgba(28,33,43,0.6), rgba(10,12,16,0.6));
    box-shadow: 0 0 0 1px rgba(210,75,61,0.2), 0 30px 80px rgba(0,0,0,0.6), inset 0 0 50px rgba(120,130,150,0.06);
    animation: qrFrameIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes qrFrameIn {
    0%   { opacity: 0; transform: scale(0.82) rotateX(18deg); }
    100% { opacity: 1; transform: scale(1) rotateX(0deg); }
}
.qr-code {
    width: 82%; height: 82%;
    object-fit: cover;
    border-radius: 8px;
    filter: drop-shadow(0 0 8px rgba(210,75,61,0.18));
    opacity: 0.95;
    /* Materialize top-to-bottom as the scanline passes — the image
       "scans into" the frozen video frame instead of just popping in. */
    animation: qrScanIn 1.5s cubic-bezier(0.4, 0, 0.2, 1) both;
}
@keyframes qrScanIn {
    0%   { clip-path: inset(0 0 100% 0); opacity: 0.15;
           filter: brightness(2.2) contrast(1.4) drop-shadow(0 0 14px rgba(210,75,61,0.6)); }
    55%  { opacity: 0.9; }
    100% { clip-path: inset(0 0 0 0); opacity: 0.95;
           filter: brightness(1) contrast(1) drop-shadow(0 0 8px rgba(210,75,61,0.18)); }
}
.qr-corner {
    position: absolute; width: 34px; height: 34px;
    border: 3px solid var(--intro-red);
    filter: drop-shadow(0 0 6px rgba(210,75,61,0.6));
    animation: cornerPulse 1.6s ease-in-out infinite;
}
.qr-corner.tl { top: 12px; left: 12px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.qr-corner.tr { top: 12px; right: 12px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.qr-corner.bl { bottom: 12px; left: 12px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.qr-corner.br { bottom: 12px; right: 12px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }
@keyframes cornerPulse { 0%,100% { opacity: 0.55; } 50% { opacity: 1; } }

.qr-scanline {
    position: absolute; left: 6%; right: 6%; height: 2px; top: 8%; border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--intro-red), transparent);
    box-shadow: 0 0 18px 4px rgba(210,75,61,0.5);
    animation: scanSweep 1.6s cubic-bezier(0.45,0,0.55,1) infinite;
}
.qr-scanline::after {
    content: ""; position: absolute; left: 0; right: 0; top: 1px; height: 60px;
    background: linear-gradient(to bottom, rgba(210,75,61,0.2), transparent);
}
@keyframes scanSweep { 0% { top: 8%; opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { top: 88%; opacity: 0; } }

.qr-frame.is-success {
    box-shadow: 0 0 0 1px rgba(210,75,61,0.6), 0 0 60px rgba(210,75,61,0.4), inset 0 0 60px rgba(210,75,61,0.18);
    animation: successPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
.qr-frame.is-success .qr-scanline { display: none; }
.qr-frame.is-success .qr-corner { border-color: var(--intro-red); opacity: 1; animation: none; }
@keyframes successPop { 0% { transform: scale(1); } 50% { transform: scale(1.06); } 100% { transform: scale(1); } }

.qr-check {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.35s ease;
}
.qr-frame.is-success .qr-check { opacity: 1; }
.qr-check svg { width: 42%; height: 42%; color: var(--intro-red); filter: drop-shadow(0 0 14px rgba(210,75,61,0.7)); }
.qr-frame.is-success .qr-code { opacity: 0.12; filter: blur(1px); }

/* ---------- Security readout ---------- */
.proc-readout {
    display: flex; flex-direction: column; align-items: center; gap: 0.9rem;
    min-width: clamp(220px, 46vw, 320px);
}

/* Rolling log of system messages */
.proc-log {
    width: clamp(220px, 46vw, 320px);
    min-height: 4.2em;
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.6rem, 1.5vw, 0.72rem);
    letter-spacing: 0.12em;
    color: rgba(185,191,202,0.55);
    text-align: left;
    line-height: 1.5;
}
.proc-log .line { opacity: 0; transform: translateY(4px); transition: opacity 0.3s ease, transform 0.3s ease; }
.proc-log .line.show { opacity: 1; transform: none; }
.proc-log .line .ok { color: var(--intro-red); }
.proc-log .line .tick { color: #6f7784; margin-right: 0.6em; }

.proc-status {
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.74rem, 1.9vw, 0.95rem);
    letter-spacing: 0.3em; text-transform: uppercase; color: #e6e8ee;
    display: flex; align-items: center; gap: 0.4rem;
    min-height: 1.4em;
}
.proc-status .dots::after { content: ""; animation: procDots 1.2s steps(4,end) infinite; }
@keyframes procDots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.proc-status.is-success { color: var(--intro-red); text-shadow: 0 0 20px rgba(210,75,61,0.5); }
/* subtle glitch flicker on the status line */
.proc-status.glitch { animation: statusGlitch 0.28s steps(2) 1; }
@keyframes statusGlitch {
    0%   { transform: translateX(0);   text-shadow: 0 0 0 transparent; }
    30%  { transform: translateX(-2px); text-shadow: 1.5px 0 rgba(210,75,61,0.7), -1.5px 0 rgba(120,180,255,0.4); }
    60%  { transform: translateX(2px); }
    100% { transform: translateX(0); }
}

.proc-bar {
    width: clamp(220px, 46vw, 320px); height: 3px; border-radius: 3px;
    background: rgba(255,255,255,0.08); overflow: hidden;
}
.proc-bar-fill {
    height: 100%; width: 0%; border-radius: 3px;
    background: linear-gradient(90deg, var(--intro-silver), var(--intro-red));
    box-shadow: 0 0 12px rgba(210,75,61,0.6);
    transition: width 0.25s linear;
}
.proc-percent {
    font-family: 'Space Mono', monospace; font-size: 0.72rem; letter-spacing: 0.2em;
    color: rgba(185,191,202,0.55);
}

/* Occasional full-screen glitch flash during processing */
.intro-glitch {
    position: absolute; inset: 0; z-index: 12; pointer-events: none; opacity: 0;
    background:
        repeating-linear-gradient(to bottom, rgba(210,75,61,0.05) 0 2px, transparent 2px 5px);
    mix-blend-mode: screen;
}
.intro-glitch.flash { animation: glitchFlash 0.18s steps(2) 1; }
@keyframes glitchFlash {
    0%   { opacity: 0; transform: translateY(0); }
    40%  { opacity: 0.8; transform: translateY(-3px); }
    70%  { opacity: 0.3; transform: translateY(2px); }
    100% { opacity: 0; transform: translateY(0); }
}

/* ==================== PORTFOLIO POWER-ON ENTRANCE ==================== */
body.intro-active .pages-container,
body.intro-active .fixed-section-title,
body.intro-active .skill-icons,
body.intro-active .cine-sound { opacity: 0; }

body.intro-reveal-in .pages-container { animation: portfolioRise 1.4s cubic-bezier(0.22,1,0.36,1) both; }
body.intro-reveal-in .skill-icons { animation: navFadeUp 1s ease 0.55s both; }
body.intro-reveal-in .cine-sound { animation: fadeUpSoft 1s ease 0.55s both; }

@keyframes portfolioRise {
    0%   { opacity: 0; transform: translateY(34px) scale(0.985); filter: blur(14px) brightness(1.6); }
    55%  { opacity: 1; filter: blur(0) brightness(1.1); }
    100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0) brightness(1); }
}
@keyframes fadeUpSoft { 0% { opacity: 0; transform: translateY(14px); } 100% { opacity: 1; transform: translateY(0); } }
/* Nav dock must keep its horizontal centering (translateX(-50%)) through the reveal */
@keyframes navFadeUp { 0% { opacity: 0; transform: translate(-50%, 14px); } 100% { opacity: 1; transform: translate(-50%, 0); } }

body.intro-reveal-in .hero-content > *,
body.intro-reveal-in .hero-3d-model {
    animation: heroStagger 0.9s cubic-bezier(0.22,1,0.36,1) both;
}
body.intro-reveal-in .hero-content > *:nth-child(1) { animation-delay: 0.5s; }
body.intro-reveal-in .hero-content > *:nth-child(2) { animation-delay: 0.6s; }
body.intro-reveal-in .hero-content > *:nth-child(3) { animation-delay: 0.7s; }
body.intro-reveal-in .hero-content > *:nth-child(4) { animation-delay: 0.8s; }
body.intro-reveal-in .hero-content > *:nth-child(5) { animation-delay: 0.9s; }
body.intro-reveal-in .hero-3d-model { animation-delay: 0.65s; }
@keyframes heroStagger {
    0%   { opacity: 0; transform: translateY(22px); filter: blur(6px); }
    100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .intro-overlay, .intro-overlay * {
        animation: none !important;
        transition: opacity 0.3s ease !important;
    }
}
