/* ============================================
   undo.quest — Chromatic Aberration Glitch UI
   ============================================ */

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

:root {
    --void-black: #0A0A0F;
    --static-gray: #1C1C28;
    --glitch-red: #FF2D2D;
    --phosphor-green: #2DFF6E;
    --screen-blue: #2D6EFF;
    --burnt-white: #E8E4DF;
    --faded-signal: #6B6878;
    --rewind-magenta: #FF2DA0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--void-black);
    color: var(--burnt-white);
    font-family: 'Inter', sans-serif;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.01em;
}

/* --- Scan Lines Overlay --- */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(0, 0, 0, 0.15) 1px,
        rgba(0, 0, 0, 0.15) 2px
    );
    opacity: 0.2;
}

/* --- Static Noise Canvas --- */
#noise-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    opacity: 0.03;
    transition: opacity 0.3s ease;
}

#noise-canvas.scrolling {
    opacity: 0.08;
}

/* --- Timeline Scrubber Bar --- */
#timeline-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.05);
    z-index: 2000;
    overflow: hidden;
}

#timeline-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--glitch-red), var(--phosphor-green), var(--screen-blue));
    transition: width 0.15s ease-out;
}

#timeline-domain {
    position: absolute;
    top: 4px;
    left: 12px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    color: var(--faded-signal);
    letter-spacing: 0.08em;
    opacity: 0;
    transition: opacity 0.2s ease;
}

#timeline-bar:hover #timeline-domain {
    opacity: 1;
}

/* --- Horizontal Scroll Container --- */
#scroll-container {
    display: grid;
    grid-template-columns: repeat(7, 100vw);
    width: 700vw;
    height: 100vh;
    overflow-x: scroll;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: auto;
    scrollbar-width: none;
}

#scroll-container::-webkit-scrollbar {
    display: none;
}

/* --- Frame Base --- */
.frame {
    position: relative;
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.frame-content {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* --- Ghost Layers --- */
.frame-ghosts {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.ghost-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    mix-blend-mode: difference;
    background: var(--static-gray);
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
}

.ghost-1 {
    opacity: 0.06;
    transform: translate(8px, -6px);
}

.ghost-2 {
    opacity: 0.04;
    transform: translate(-10px, 10px);
}

.ghost-3 {
    opacity: 0.05;
    transform: translate(12px, 5px);
}

.ghost-4 {
    opacity: 0.04;
    transform: translate(-6px, -12px);
}

.ghost-5 {
    opacity: 0.03;
    transform: translate(15px, -3px);
}

/* --- Glitch Tear Strips --- */
.glitch-tear {
    position: absolute;
    top: var(--tear-top, 50%);
    left: 0;
    width: 100%;
    height: var(--tear-height, 4px);
    background: var(--void-black);
    transform: translateX(var(--tear-offset, 0px));
    z-index: 20;
    animation: glitchTear 6s steps(1) infinite;
}

@keyframes glitchTear {
    0% { transform: translateX(var(--tear-offset, 0px)); }
    15% { transform: translateX(calc(var(--tear-offset, 0px) * -0.7)); }
    15.5% { transform: translateX(var(--tear-offset, 0px)); }
    40% { transform: translateX(calc(var(--tear-offset, 0px) * 1.3)); }
    40.5% { transform: translateX(var(--tear-offset, 0px)); }
    70% { transform: translateX(calc(var(--tear-offset, 0px) * -1.1)); }
    70.5% { transform: translateX(var(--tear-offset, 0px)); }
    100% { transform: translateX(var(--tear-offset, 0px)); }
}

/* --- Chromatic Aberration Headings --- */
.chromatic-heading {
    position: relative;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    letter-spacing: 0.08em;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    text-align: center;
    line-height: 1.3;
}

.chromatic-heading .chr-red,
.chromatic-heading .chr-green,
.chromatic-heading .chr-blue {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

.chromatic-heading .chr-red {
    color: var(--glitch-red);
    transform: translate(-3px, 1px);
    mix-blend-mode: screen;
    opacity: 0.6;
    animation: chromaticJitterRed 0.5s steps(3) infinite;
}

.chromatic-heading .chr-green {
    color: var(--phosphor-green);
    transform: translate(2px, -1px);
    mix-blend-mode: screen;
    opacity: 0.6;
    animation: chromaticJitterGreen 0.7s steps(3) infinite;
}

.chromatic-heading .chr-blue {
    color: var(--screen-blue);
    transform: translate(0, 0);
    position: relative;
}

@keyframes chromaticJitterRed {
    0% { transform: translate(-3px, 1px); }
    33% { transform: translate(-4px, 0px); }
    66% { transform: translate(-2px, 2px); }
    100% { transform: translate(-3px, 1px); }
}

@keyframes chromaticJitterGreen {
    0% { transform: translate(2px, -1px); }
    33% { transform: translate(3px, 0px); }
    66% { transform: translate(1px, -2px); }
    100% { transform: translate(2px, -1px); }
}

/* ============================================
   FRAME 1: The Error State
   ============================================ */
#frame-1 {
    background: var(--void-black);
}

#frame-1 #scanlines {
    opacity: 0.2;
}

.bungee-hero {
    font-family: 'Bungee Shade', cursive;
    font-size: clamp(6rem, 20vw, 16rem);
    font-weight: 400;
    letter-spacing: 0.05em;
    line-height: 1;
}

.bungee-hero .chr-red {
    transform: translate(-8px, 3px);
    animation: heroJitterRed 0.3s steps(1) infinite;
}

.bungee-hero .chr-green {
    transform: translate(5px, -3px);
    animation: heroJitterGreen 0.5s steps(1) infinite;
}

.bungee-hero .chr-blue {
    animation: heroFlicker 2s steps(1) infinite;
}

@keyframes heroJitterRed {
    0% { transform: translate(-8px, 3px); }
    20% { transform: translate(-6px, 4px); }
    40% { transform: translate(-9px, 2px); }
    60% { transform: translate(-7px, 3px); }
    80% { transform: translate(-8px, 5px); }
    100% { transform: translate(-8px, 3px); }
}

@keyframes heroJitterGreen {
    0% { transform: translate(5px, -3px); }
    25% { transform: translate(6px, -2px); }
    50% { transform: translate(4px, -4px); }
    75% { transform: translate(7px, -3px); }
    100% { transform: translate(5px, -3px); }
}

@keyframes heroFlicker {
    0% { opacity: 1; }
    7% { opacity: 0.85; }
    10% { opacity: 1; }
    35% { opacity: 1; }
    38% { opacity: 0.85; }
    40% { opacity: 1; }
    72% { opacity: 1; }
    73% { opacity: 0.88; }
    76% { opacity: 1; }
    100% { opacity: 1; }
}

#blink-cursor {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 2rem;
    color: var(--burnt-white);
    margin-top: 1rem;
    animation: blink 1s steps(1) infinite;
}

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

/* ============================================
   FRAME 2: The Question
   ============================================ */
#frame-2 {
    background: var(--static-gray);
}

#typewriter-text {
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    min-height: 1.5em;
    padding: 0 2rem;
    max-width: 90vw;
}

#ghost-question {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(calc(-50% + 10px), calc(-50% - 8px));
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    letter-spacing: 0.08em;
    color: var(--faded-signal);
    opacity: 0.08;
    pointer-events: none;
    white-space: nowrap;
}

/* ============================================
   FRAME 3: The Archive
   ============================================ */
#frame-3 {
    background: var(--void-black);
}

.archive-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: 1.5rem;
    padding: 5vh 8vw;
    width: 100%;
    max-width: 1200px;
    align-content: center;
}

.memory-card {
    border: 1px solid var(--faded-signal);
    padding: 1.2rem 1rem;
    background: rgba(28, 28, 40, 0.4);
    transform: rotate(var(--card-rotate, 0deg)) translate(var(--card-x, 0px), var(--card-y, 0px));
    transition: border-color 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    position: relative;
}

.memory-card:hover {
    border-color: var(--rewind-magenta);
    box-shadow: 0 0 20px rgba(255, 45, 160, 0.15);
    transform: rotate(0deg) translate(0px, 0px) scale(1.02);
}

.memory-card:hover ~ .frame-ghosts .ghost-layer {
    transform: translate(20px, -15px);
}

.card-clipped {
    clip-path: inset(0 0 0 0);
    margin-right: -3vw;
}

.card-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--faded-signal);
    line-height: 1.6;
    letter-spacing: 0.04em;
}

.memory-card:hover .card-text {
    color: var(--burnt-white);
}

/* ============================================
   FRAME 4: The Rewind
   ============================================ */
#frame-4 {
    background: var(--void-black);
}

#frame-4.flash-1 { background: var(--static-gray); }
#frame-4.flash-2 { background: var(--screen-blue); }
#frame-4.flash-3 { background: var(--void-black); }

#undo-arrow-container {
    width: clamp(200px, 40vw, 400px);
    margin-bottom: 3rem;
}

#undo-arrow {
    width: 100%;
    height: auto;
}

.arrow-main,
.arrow-ghost {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 1.5s ease-in-out;
}

.arrow-ghost-red {
    opacity: 0.3;
    transform: translate(-3px, 1px);
}

.arrow-ghost-green {
    opacity: 0.3;
    transform: translate(2px, -1px);
}

.arrow-main {
    opacity: 0.3;
}

#frame-4.in-view .arrow-main,
#frame-4.in-view .arrow-ghost {
    stroke-dashoffset: 0;
}

#rewind-text {
    font-size: clamp(1.4rem, 3vw, 2.5rem);
    padding: 0 2rem;
}

/* ============================================
   FRAME 5: The Residue
   ============================================ */
#frame-5 {
    background: var(--void-black);
}

#frame-5 .ghost-layer {
    opacity: 0.08;
}

#frame-5 .ghost-1 { transform: translate(10px, -8px); }
#frame-5 .ghost-2 { transform: translate(-12px, 12px); }
#frame-5 .ghost-3 { transform: translate(15px, 6px); }
#frame-5 .ghost-4 { transform: translate(-8px, -15px); }
#frame-5 .ghost-5 { transform: translate(18px, -4px); }

#residue-content {
    max-width: 700px;
    padding: 0 2rem;
    position: relative;
}

.residue-paragraph {
    font-family: 'Inter', sans-serif;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    color: var(--burnt-white);
    line-height: 1.75;
    letter-spacing: 0.01em;
    text-align: left;
}

#frame-5 .glitch-tear {
    animation-duration: 3s;
}

/* ============================================
   FRAME 6: The Paradox
   ============================================ */
#frame-6 {
    background: var(--void-black);
}

#paradox-split {
    width: 100%;
    height: 100%;
    display: flex;
    position: relative;
}

#paradox-left {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: invert(1);
    background: var(--void-black);
    clip-path: polygon(0 0, 60% 0, 40% 100%, 0 100%);
    z-index: 2;
}

#paradox-left .paradox-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    font-size: clamp(1.4rem, 3vw, 2.5rem);
    letter-spacing: 0.08em;
    text-align: center;
    padding: 0 15vw 0 5vw;
}

#paradox-right {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

#paradox-right .paradox-text {
    font-size: clamp(1.4rem, 3vw, 2.5rem);
    padding: 0 5vw 0 15vw;
}

#paradox-divider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
    background: linear-gradient(
        145deg,
        transparent calc(50% - 1px),
        var(--rewind-magenta) calc(50% - 1px),
        var(--rewind-magenta) calc(50% + 1px),
        transparent calc(50% + 1px)
    );
    opacity: 0.5;
    animation: dividerJitter 0.8s steps(1) infinite;
}

@keyframes dividerJitter {
    0% { transform: translateX(0px); }
    20% { transform: translateX(3px); }
    40% { transform: translateX(-2px); }
    60% { transform: translateX(5px); }
    80% { transform: translateX(-3px); }
    100% { transform: translateX(0px); }
}

/* ============================================
   FRAME 7: The Void
   ============================================ */
#frame-7 {
    background: var(--void-black);
}

#frame-7 .frame-content {
    align-items: center;
    justify-content: center;
}

#void-line {
    width: 0;
    height: 1px;
    background: var(--burnt-white);
    transition: width 1.5s ease-out;
}

#frame-7.in-view #void-line {
    width: 50vw;
}

#void-domain {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1rem;
    font-weight: 400;
    color: var(--burnt-white);
    letter-spacing: 0.08em;
    margin-top: 1.5rem;
    opacity: 0;
    transition: opacity 1s ease 0.8s;
}

#frame-7.in-view #void-domain {
    opacity: 1;
}

/* ============================================
   Utility: Frame visibility states
   ============================================ */
.frame.rewinding .chromatic-heading .chr-red {
    animation-duration: 0.15s;
}

.frame.rewinding .chromatic-heading .chr-green {
    animation-duration: 0.2s;
}

/* Increased scan line opacity for frame 5 */
#frame-5.in-view ~ #scanlines {
    opacity: 0.25;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .archive-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        padding: 3vh 5vw;
    }

    .bungee-hero {
        font-size: clamp(3rem, 15vw, 8rem);
    }

    .bungee-hero .chr-red {
        transform: translate(-5px, 2px);
    }

    .bungee-hero .chr-green {
        transform: translate(3px, -2px);
    }

    #paradox-left .paradox-text,
    #paradox-right .paradox-text {
        padding: 0 3vw;
        font-size: clamp(1rem, 4vw, 1.8rem);
    }
}
