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

html {
    scroll-behavior: smooth;
}

body {
    background: #1a0510;
    color: #e8d0d8;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: clamp(0.88rem, 1.1vw, 1.05rem);
    letter-spacing: 0.03em;
    line-height: 1.72;
    overflow-x: hidden;
}

/* === Scanlines === */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 1px,
        rgba(0,0,0,0.06) 1px,
        rgba(0,0,0,0.06) 2px
    );
}

/* === Vignette === */
#vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    background: radial-gradient(ellipse at center, transparent 40%, #1a0510 100%);
}

/* === Film Grain Canvas === */
#grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9997;
    opacity: 0.015;
}

/* === Lens Flares === */
.lens-flare {
    position: fixed;
    pointer-events: none;
    z-index: 1;
    border-radius: 50%;
}

#flare-1 {
    width: 40vw;
    height: 40vw;
    top: -10vw;
    right: -10vw;
    background: radial-gradient(circle, rgba(196,149,106,0.12) 0%, rgba(200,112,144,0.06) 40%, transparent 70%);
    animation: flare-drift-1 30s ease-in-out infinite;
}

#flare-2 {
    width: 35vw;
    height: 35vw;
    bottom: -5vw;
    left: -10vw;
    background: radial-gradient(circle, rgba(200,112,144,0.08) 0%, rgba(196,149,106,0.04) 50%, transparent 70%);
    animation: flare-drift-2 38s ease-in-out infinite;
    opacity: 0;
}

@keyframes flare-drift-1 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-3vw, 2vw); }
}

@keyframes flare-drift-2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(4vw, -3vw); }
}

/* === Navigation === */
#nav-cursor {
    position: fixed;
    top: 2rem;
    left: 2rem;
    z-index: 10000;
}

.cursor-glyph {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 2rem;
    color: #fff5f0;
    animation: blink-cursor 1.2s infinite;
    cursor: pointer;
    display: block;
}

.nav-labels {
    list-style: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
    margin-top: 0.5rem;
}

#nav-cursor:hover .nav-labels {
    opacity: 1;
    pointer-events: all;
}

.nav-labels li {
    transform: translateY(8px);
    opacity: 0;
    transition: transform 280ms ease, opacity 280ms ease;
}

#nav-cursor:hover .nav-labels li {
    transform: translateY(0);
    opacity: 1;
}

#nav-cursor:hover .nav-labels li:nth-child(1) { transition-delay: 0ms; }
#nav-cursor:hover .nav-labels li:nth-child(2) { transition-delay: 60ms; }
#nav-cursor:hover .nav-labels li:nth-child(3) { transition-delay: 120ms; }
#nav-cursor:hover .nav-labels li:nth-child(4) { transition-delay: 180ms; }

.nav-labels a {
    font-family: 'Archivo Narrow', sans-serif;
    font-weight: 500;
    font-size: clamp(0.68rem, 0.85vw, 0.78rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #8a5060;
    text-decoration: none;
    display: block;
    padding: 0.3rem 0;
    transition: color 200ms ease;
}

.nav-labels a:hover {
    color: #c87090;
}

/* === Blink Cursor === */
@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.1; }
}

.blink-cursor {
    animation: blink-cursor 1.2s infinite;
    color: #fff5f0;
}

/* === Scenes === */
.scene {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
}

/* === Scene 1: Boot === */
#scene-1 {
    flex-direction: column;
    background: #1a0510;
}

.boot-terminal {
    margin-bottom: 3rem;
}

.boot-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.88rem, 1.2vw, 1.1rem);
    color: #c87090;
    line-height: 2;
    white-space: pre-wrap;
}

.main-headline {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.08em;
    line-height: 1.05;
    text-transform: uppercase;
    color: #f0d4dc;
    text-shadow: 0 0 30px rgba(200,112,144,0.15);
    opacity: 0;
    transition: opacity 1.5s ease;
    text-align: center;
    padding: 0 1rem;
}

.main-headline.visible {
    opacity: 1;
}

/* === Scene 2: Broken Registry === */
#scene-2 {
    background: #2a0a1a;
    align-items: flex-start;
    padding: 8vh 4vw;
}

.broken-grid {
    display: grid;
    grid-template-columns: 0.8fr 1.6fr 0.4fr 1.2fr 0.6fr 1.8fr 0.3fr 1.4fr 0.9fr;
    grid-template-rows: auto auto;
    gap: 2rem;
    width: 100%;
    min-height: 100vh;
    align-content: center;
}

.terminal-window {
    border: 1px solid #6b3a4a;
    background: rgba(42,10,26,0.8);
    padding: 0;
    position: relative;
    transition: transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 280ms ease;
}

.terminal-window:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 24px rgba(26,5,16,0.4);
}

.tw-1 {
    grid-column: 1 / 4;
    grid-row: 1;
    transform: rotate(-0.8deg);
}

.tw-2 {
    grid-column: 5 / 9;
    grid-row: 1;
    transform: rotate(1.2deg);
}

.tw-3 {
    grid-column: 2 / 6;
    grid-row: 2;
    transform: rotate(0.5deg);
}

.tw-4 {
    grid-column: 6 / 10;
    grid-row: 2;
    transform: rotate(-1.5deg);
}

.tw-title {
    font-family: 'Archivo Narrow', sans-serif;
    font-weight: 500;
    font-size: clamp(0.68rem, 0.85vw, 0.78rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #c4956a;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #4a1a2e;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tw-title::after {
    content: '_';
    animation: blink-cursor 1.2s infinite;
    color: #fff5f0;
}

.tw-content {
    padding: 1.2rem 1rem;
    color: rgba(232,208,216,0.88);
}

/* Reveal animation for terminal windows */
[data-reveal] {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease, transform 600ms ease;
}

[data-reveal].revealed {
    opacity: 1;
}

[data-reveal].revealed.tw-1 { transform: translateY(0) rotate(-0.8deg); }
[data-reveal].revealed.tw-2 { transform: translateY(0) rotate(1.2deg); }
[data-reveal].revealed.tw-3 { transform: translateY(0) rotate(0.5deg); }
[data-reveal].revealed.tw-4 { transform: translateY(0) rotate(-1.5deg); }

/* === Scene 3: Layer Peel === */
#scene-3 {
    background: #1a0510;
}

.layer-stack {
    position: relative;
    width: clamp(300px, 50vw, 600px);
    height: clamp(300px, 50vw, 600px);
}

.identity-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s linear;
}

.layer-bottom {
    background: #c87090;
    z-index: 1;
}

.layer-middle {
    background: #6b3a4a;
    z-index: 2;
    transform: translate(6px, -6px);
}

.layer-top {
    background: #4a1a2e;
    z-index: 3;
    transform: translate(12px, -12px);
}

.layer-label {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: clamp(2.2rem, 7vw, 6.4rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #f0d4dc;
    text-shadow: 0 0 30px rgba(200,112,144,0.15);
}

/* === Scene 4: Archive === */
#scene-4 {
    background: #2a0a1a;
}

.archive-window {
    width: clamp(320px, 70vw, 800px);
    height: 70vh;
    transform: rotate(1.2deg);
    overflow: hidden;
}

.archive-scroll {
    height: calc(100% - 2.5rem);
    overflow: hidden;
    position: relative;
}

.archive-content {
    animation: archive-scroll 30s linear infinite;
}

@keyframes archive-scroll {
    0% { transform: translateY(0); }
    100% { transform: translateY(-50%); }
}

.archive-content p {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(74,26,46,0.5);
    font-size: clamp(0.75rem, 0.9vw, 0.9rem);
}

.timestamp {
    color: #c4956a;
}

.hash {
    color: #c87090;
}

/* === Scene 5: Fade === */
.scene-fade {
    min-height: 80vh;
    background: #1a0510;
    flex-direction: column;
}

.fade-content {
    text-align: center;
}

.large-cursor {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: clamp(4rem, 10vw, 8rem);
    color: #fff5f0;
    animation: blink-cursor 1.2s infinite;
    display: block;
    margin-bottom: 2rem;
}

.fade-label {
    font-family: 'Archivo Narrow', sans-serif;
    font-weight: 500;
    font-size: clamp(0.68rem, 0.85vw, 0.78rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #8a5060;
}

/* === Responsive === */
@media (max-width: 768px) {
    .broken-grid {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
        padding: 2rem 1rem;
    }

    .tw-1, .tw-2, .tw-3, .tw-4 {
        transform: rotate(0) !important;
    }

    [data-reveal].revealed.tw-1,
    [data-reveal].revealed.tw-2,
    [data-reveal].revealed.tw-3,
    [data-reveal].revealed.tw-4 {
        transform: translateY(0) rotate(0) !important;
    }

    .layer-stack {
        width: 80vw;
        height: 80vw;
    }
}
