/* ===================================
   monopole.bar - Cinematic Contact Sheet
   Film noir science documentary aesthetic
   =================================== */

/* --- CSS Custom Properties --- */
:root {
    --film-black: #0A0C0A;
    --frame-dark: #141814;
    --green-white: #E0E8E0;
    --grey-green: #A0A8A0;
    --neon-green: #40E060;
    --neon-amber: #E0A020;
    --particle-red: #E04040;
    --frame-border: rgba(64, 224, 96, 0.3);
    --frame-border-hover: rgba(64, 224, 96, 0.6);

    --font-display: 'Courier Prime', 'Courier New', monospace;
    --font-body: 'Source Serif 4', 'Georgia', serif;
    --font-tech: 'IBM Plex Mono', 'Consolas', monospace;

    --gap: 4px;
    --columns: 4;
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--film-black);
    color: var(--green-white);
    font-family: var(--font-body);
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Film Grain Overlay --- */
#film-grain {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    animation: grain 0.5s steps(6) infinite;
}

@keyframes grain {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-1px, -1px); }
    20% { transform: translate(1px, 0); }
    30% { transform: translate(0, 1px); }
    40% { transform: translate(-1px, 1px); }
    50% { transform: translate(1px, -1px); }
    60% { transform: translate(0, 0); }
    70% { transform: translate(1px, 1px); }
    80% { transform: translate(-1px, 0); }
    90% { transform: translate(0, -1px); }
}

/* --- Particle Trail SVGs --- */
#particle-trails {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity 1s ease;
}

#particle-trails.active {
    opacity: 1;
}

.particle-trail {
    fill: none;
    stroke: var(--neon-green);
    stroke-opacity: 0.2;
    stroke-width: 1;
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: trailFlow 12s linear infinite;
}

.trail-2 { animation-delay: -2s; }
.trail-3 { animation-delay: -4s; }
.trail-4 { animation-delay: -6s; }
.trail-5 { animation-delay: -8s; }

.trail-fork-1,
.trail-fork-2,
.trail-fork-3,
.trail-fork-4 {
    stroke-width: 0.5;
    stroke-opacity: 0.15;
    stroke-dasharray: 200;
    animation: trailFlow 8s linear infinite;
}

.trail-fork-2 { animation-delay: -2s; }
.trail-fork-3 { animation-delay: -4s; }
.trail-fork-4 { animation-delay: -6s; }

@keyframes trailFlow {
    from { stroke-dashoffset: 800; }
    to { stroke-dashoffset: -800; }
}

/* --- Opening Sequence --- */
#opening-sequence {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--film-black);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

#opening-sequence.fade-out {
    opacity: 0;
    pointer-events: none;
}

#opening-sequence.hidden {
    display: none;
}

#scan-line {
    position: absolute;
    top: 50%;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--neon-green);
    box-shadow: 0 0 12px var(--neon-green), 0 0 30px rgba(64, 224, 96, 0.4);
    transform: translateY(-50%);
    animation: scanDraw 1.5s ease-out forwards;
}

@keyframes scanDraw {
    0% { width: 0; opacity: 1; }
    90% { width: 100%; opacity: 1; }
    95% { width: 100%; opacity: 1; }
    100% { width: 100%; opacity: 0.6; }
}

#scan-line.pulse {
    animation: scanPulse 0.3s ease-out forwards;
}

@keyframes scanPulse {
    0% { opacity: 0.6; box-shadow: 0 0 12px var(--neon-green), 0 0 30px rgba(64, 224, 96, 0.4); }
    50% { opacity: 1; box-shadow: 0 0 24px var(--neon-green), 0 0 60px rgba(64, 224, 96, 0.6); }
    100% { opacity: 0; box-shadow: 0 0 0 transparent; }
}

#first-frame-preview {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 170px;
    opacity: 0;
}

#first-frame-preview.visible {
    opacity: 1;
}

.frame-border-anim {
    width: 100%;
    height: 100%;
    border: 1px solid var(--neon-green);
    opacity: 0;
    animation: frameBorderDraw 0.6s ease-out forwards;
    animation-play-state: paused;
}

#first-frame-preview.visible .frame-border-anim {
    animation-play-state: running;
}

@keyframes frameBorderDraw {
    0% { opacity: 0; clip-path: inset(0 100% 100% 0); }
    25% { clip-path: inset(0 0 100% 0); }
    50% { clip-path: inset(0 0 0 0); opacity: 1; }
    100% { clip-path: inset(0 0 0 0); opacity: 1; }
}

/* --- Masonry Contact Sheet --- */
#contact-sheet {
    position: relative;
    z-index: 2;
    columns: var(--columns);
    column-gap: var(--gap);
    padding: 20px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#contact-sheet.visible {
    opacity: 1;
}

/* --- Film Frame --- */
.film-frame {
    break-inside: avoid;
    position: relative;
    background: var(--frame-dark);
    border: 1px solid var(--frame-border);
    margin-bottom: var(--gap);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    opacity: 0;
    transform: translateY(20px);
}

.film-frame.revealed {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.6s ease, transform 0.6s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.film-frame:hover {
    transform: scale(1.02);
    border-color: var(--frame-border-hover);
    box-shadow: 0 0 20px rgba(64, 224, 96, 0.1);
}

/* Aspect Ratios */
.aspect-widescreen {
    aspect-ratio: 16 / 9;
}

.aspect-anamorphic {
    aspect-ratio: 2.39 / 1;
}

.aspect-classic {
    aspect-ratio: 4 / 3;
}

/* Frame Number */
.frame-number {
    position: absolute;
    top: 8px;
    left: 8px;
    font-family: var(--font-tech);
    font-size: 0.65rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--neon-green);
    opacity: 0.6;
    z-index: 3;
}

/* Letterbox Bars */
.frame-letterbox {
    width: 100%;
    height: 8px;
    background: var(--film-black);
    flex-shrink: 0;
}

/* Frame Content */
.frame-content {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    position: relative;
    z-index: 2;
}

.aspect-widescreen .frame-content,
.aspect-anamorphic .frame-content {
    padding-top: 16px;
    padding-bottom: 16px;
}

/* Typewriter Text */
.typewriter {
    font-family: var(--font-display);
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--green-white);
    margin-bottom: 12px;
    position: relative;
    overflow: hidden;
}

.typewriter .typed-text {
    display: inline;
}

.typewriter .cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--neon-green);
    vertical-align: text-bottom;
    margin-left: 2px;
    animation: blink 1s step-end infinite;
}

.typewriter .cursor.fade-out {
    animation: cursorFade 0.5s ease-out forwards;
}

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

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

.typewriter-sub {
    font-family: var(--font-display);
    font-size: clamp(0.8rem, 1.5vw, 1.1rem);
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--grey-green);
    overflow: hidden;
}

.typewriter-sub .typed-text {
    display: inline;
}

.typewriter-sub .cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--neon-green);
    vertical-align: text-bottom;
    margin-left: 2px;
    animation: blink 1s step-end infinite;
}

.typewriter-sub .cursor.fade-out {
    animation: cursorFade 0.5s ease-out forwards;
}

/* Body Text */
.body-text {
    font-family: var(--font-body);
    font-size: 0.95rem;
    line-height: 1.75;
    font-weight: 400;
    color: var(--grey-green);
}

/* Frame Annotation */
.frame-annotation {
    display: inline-block;
    margin-top: 12px;
    font-family: var(--font-tech);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--neon-amber);
    padding: 4px 8px;
    border: 1px solid rgba(224, 160, 32, 0.3);
}

/* --- Glitch Effect --- */
.glitch-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 4;
    opacity: 0;
}

.film-frame.glitch .glitch-layer {
    animation: glitchEffect 150ms linear forwards;
}

.glitch-layer::before,
.glitch-layer::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.film-frame.glitch .glitch-layer::before {
    background: rgba(224, 64, 64, 0.08);
    clip-path: inset(20% 0 60% 0);
    transform: translateX(3px);
    animation: glitchSlice1 150ms linear;
}

.film-frame.glitch .glitch-layer::after {
    background: rgba(64, 224, 224, 0.08);
    clip-path: inset(50% 0 20% 0);
    transform: translateX(-3px);
    animation: glitchSlice2 150ms linear;
}

@keyframes glitchEffect {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes glitchSlice1 {
    0% { clip-path: inset(20% 0 60% 0); transform: translateX(3px); }
    33% { clip-path: inset(45% 0 30% 0); transform: translateX(-2px); }
    66% { clip-path: inset(10% 0 70% 0); transform: translateX(4px); }
    100% { clip-path: inset(30% 0 50% 0); transform: translateX(0); }
}

@keyframes glitchSlice2 {
    0% { clip-path: inset(50% 0 20% 0); transform: translateX(-3px); }
    33% { clip-path: inset(70% 0 10% 0); transform: translateX(2px); }
    66% { clip-path: inset(35% 0 45% 0); transform: translateX(-4px); }
    100% { clip-path: inset(60% 0 25% 0); transform: translateX(0); }
}

/* --- Frame Overlay (Expanded View) --- */
#frame-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 12, 10, 0.85);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-out;
}

#frame-overlay.active {
    opacity: 1;
    pointer-events: all;
}

#expanded-frame {
    width: 80%;
    max-width: 900px;
    max-height: 80vh;
    background: var(--frame-dark);
    border: 1px solid var(--frame-border-hover);
    box-shadow: 0 0 40px rgba(64, 224, 96, 0.15);
    padding: 40px;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.4s ease-out;
}

#frame-overlay.active #expanded-frame {
    transform: scale(1);
}

#expanded-frame .frame-number {
    position: relative;
    top: 0;
    left: 0;
    display: block;
    margin-bottom: 16px;
    font-size: 0.75rem;
}

#expanded-frame h2 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--green-white);
    margin-bottom: 20px;
}

#expanded-frame h1 {
    font-family: var(--font-display);
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--green-white);
    margin-bottom: 12px;
}

#expanded-frame p {
    font-family: var(--font-body);
    font-size: 1.1rem;
    line-height: 1.85;
    color: var(--grey-green);
    margin-bottom: 16px;
}

#expanded-frame .frame-annotation {
    margin-top: 20px;
    font-size: 0.8rem;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    :root {
        --columns: 3;
    }
}

@media (max-width: 768px) {
    :root {
        --columns: 2;
    }

    #contact-sheet {
        padding: 12px;
    }

    .frame-content {
        padding: 16px 14px;
    }

    #expanded-frame {
        width: 92%;
        padding: 24px;
    }
}

@media (max-width: 480px) {
    :root {
        --columns: 1;
    }

    .film-frame {
        aspect-ratio: auto !important;
    }

    .frame-content {
        padding: 20px 16px;
    }
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--film-black);
}

::-webkit-scrollbar-thumb {
    background: rgba(64, 224, 96, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(64, 224, 96, 0.4);
}

/* --- Selection --- */
::selection {
    background: rgba(64, 224, 96, 0.25);
    color: var(--green-white);
}
