/* ========================================
   parallel.quest - Opulent Sci-Fi Observatory
   ======================================== */

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: #1A0F2E;
    color: #E8DFD0;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.75;
    letter-spacing: 0.015em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- SVG Grain Filter (hidden) --- */
.grain-svg {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* --- Grain Overlay --- */
.grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    z-index: 1000;
    pointer-events: none;
    filter: url(#grain-filter);
    opacity: 0.08;
    transition: opacity 300ms ease;
}

.grain-overlay.grain-intense {
    opacity: 0.12;
}

.grain-overlay.grain-max {
    opacity: 0.10;
}

/* --- Parallax Background Layer (z-0) --- */
.parallax-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    will-change: transform;
}

.bg-grid {
    position: absolute;
    top: -20%;
    left: -20%;
    width: 140%;
    height: 140%;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(196, 163, 90, 0.04) 0px,
            transparent 1px,
            transparent 30px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(196, 163, 90, 0.04) 0px,
            transparent 1px,
            transparent 30px
        ),
        repeating-linear-gradient(
            0deg,
            rgba(196, 163, 90, 0.08) 0px,
            transparent 1px,
            transparent 120px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(196, 163, 90, 0.08) 0px,
            transparent 1px,
            transparent 120px
        );
    transform: rotate(2.5deg);
    opacity: 0.5;
}

.bg-grid-rotating {
    position: absolute;
    top: -30%;
    left: -30%;
    width: 160%;
    height: 160%;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(42, 27, 61, 0.08) 0px,
            transparent 1px,
            transparent 60px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(42, 27, 61, 0.08) 0px,
            transparent 1px,
            transparent 60px
        );
    animation: gridRotate 120s linear infinite;
}

@keyframes gridRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* --- Parallax Foreground Layer (z-2) --- */
.parallax-fg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    pointer-events: none;
    will-change: transform;
}

.coord-annotation {
    position: absolute;
    animation: coordDrift 20s ease-in-out infinite;
}

.coord-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #C4A35A;
    opacity: 0.4;
    white-space: nowrap;
}

.coord-1 { top: 8%; left: 5%; animation-delay: 0s; }
.coord-2 { top: 22%; right: 4%; animation-delay: -3s; }
.coord-3 { top: 38%; left: 3%; animation-delay: -7s; }
.coord-4 { top: 52%; right: 6%; animation-delay: -11s; }
.coord-5 { top: 66%; left: 7%; animation-delay: -2s; }
.coord-6 { top: 78%; right: 3%; animation-delay: -9s; }
.coord-7 { top: 88%; left: 2%; animation-delay: -5s; }
.coord-8 { top: 95%; right: 8%; animation-delay: -14s; }

@keyframes coordDrift {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

/* --- Sections --- */
.section {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    width: 100%;
}

/* --- Opening Threshold Section --- */
.section-opening {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(180deg, #1A0F2E 0%, #0D1B2A 100%);
}

.opening-content {
    display: grid;
    grid-template-columns: 4fr 6fr;
    width: 90%;
    max-width: 1400px;
    align-items: center;
    gap: 2rem;
}

.astrolabe-fragment {
    display: flex;
    justify-content: center;
    align-items: center;
}

.astrolabe-svg {
    width: 100%;
    max-width: 400px;
    height: auto;
}

.astrolabe-large {
    max-width: 500px;
}

.opening-text {
    padding-left: 2rem;
}

.site-title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(4rem, 10vw, 8rem);
    letter-spacing: 0.01em;
    line-height: 1.15;
    color: #E0115F;
    margin-bottom: 1rem;
}

.site-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #C4A35A;
}

/* --- Threshold Dividers --- */
.threshold-divider {
    position: relative;
    z-index: 10;
    height: 40px;
    overflow: hidden;
}

.threshold-lines {
    position: absolute;
    top: 0;
    left: -100%;
    width: 300%;
    height: 100%;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(196, 163, 90, 0.35) 0px,
            transparent 1px,
            transparent 4px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(196, 163, 90, 0.12) 0px,
            transparent 1px,
            transparent 20px
        );
    animation: thresholdSlide 30s linear infinite;
}

.threshold-mini {
    height: 24px;
    margin: 2rem 0;
}

.threshold-mini .threshold-lines {
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(196, 163, 90, 0.2) 0px,
            transparent 1px,
            transparent 6px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(196, 163, 90, 0.08) 0px,
            transparent 1px,
            transparent 30px
        );
}

@keyframes thresholdSlide {
    from { transform: translateX(0); }
    to { transform: translateX(33.33%); }
}

/* --- Observatory Panels --- */
.observatory-panel {
    position: relative;
    background: rgba(42, 27, 61, 0.7);
    border: 1px solid #C4A35A;
    padding: clamp(2rem, 4vw, 3.5rem);
    clip-path: polygon(
        0% 4%,
        4% 0%,
        96% 0%,
        100% 4%,
        100% 96%,
        96% 100%,
        4% 100%,
        0% 96%
    );
}

/* Amethyst Crown hover glow */
.observatory-panel:hover {
    box-shadow: 0 0 40px rgba(106, 61, 154, 0.15), inset 0 0 30px rgba(106, 61, 154, 0.05);
    border-color: #6A3D9A;
    transition: box-shadow 400ms cubic-bezier(0.22, 1, 0.36, 1), border-color 400ms cubic-bezier(0.22, 1, 0.36, 1);
}

.observatory-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(196, 163, 90, 0.03) 0px,
            transparent 1px,
            transparent 20px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(196, 163, 90, 0.03) 0px,
            transparent 1px,
            transparent 20px
        );
    pointer-events: none;
}

.panel-coord {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #C4A35A;
    opacity: 0.6;
    margin-bottom: 1rem;
}

.section-headline {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(2.2rem, 5.5vw, 4.8rem);
    letter-spacing: 0.01em;
    line-height: 1.15;
    color: #E0115F;
    margin-bottom: 1.5rem;
}

/* Secondary headline color variant (Emerald Depth) */
.entry-right .section-headline {
    color: #2D8B6F;
}

.section-body {
    color: #E8DFD0;
    margin-bottom: 1.25rem;
    max-width: 65ch;
}

.section-body:last-of-type {
    margin-bottom: 1.5rem;
}

.panel-metadata {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.65rem, 0.9vw, 0.8rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #8A7E70;
    margin-top: 1rem;
}

/* --- Panel Arc Decorations --- */
.panel-arc {
    position: absolute;
    width: 120px;
    height: 120px;
    border: 1px solid rgba(196, 163, 90, 0.2);
    border-radius: 50%;
    pointer-events: none;
}

.arc-top-right {
    top: -40px;
    right: -40px;
    border-bottom: none;
    border-left: none;
}

.arc-top-left {
    top: -40px;
    left: -40px;
    border-bottom: none;
    border-right: none;
}

.arc-bottom-right {
    bottom: -40px;
    right: -40px;
    border-top: none;
    border-left: none;
}

/* --- Diamond Bullet Points --- */
.section-body::before {
    display: none;
}

/* --- Section: First Observation --- */
.section-observation {
    padding: clamp(4rem, 8vh, 8rem) clamp(1rem, 5vw, 4rem);
    background: #1A0F2E;
}

.observation-grid {
    display: grid;
    grid-template-columns: 5fr 7fr;
    gap: clamp(2rem, 4vw, 4rem);
    max-width: 1400px;
    margin: 0 auto;
    align-items: center;
}

.observation-left {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- Section: Dimensional Catalogue --- */
.section-catalogue {
    padding: clamp(2rem, 4vh, 4rem) clamp(1rem, 5vw, 4rem);
    background: linear-gradient(180deg, #0D1B2A 0%, #1A0F2E 50%, #0D1B2A 100%);
}

.catalogue-entry {
    max-width: 900px;
    margin-bottom: 0;
}

.entry-left {
    margin-left: 5%;
    margin-right: auto;
}

.entry-right {
    margin-left: auto;
    margin-right: 5%;
}

/* --- Section: Convergence --- */
.section-convergence {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at center, #2A1B3D 0%, #1A0F2E 60%, #0D1B2A 100%);
    text-align: center;
    padding: clamp(4rem, 8vh, 8rem) clamp(1rem, 5vw, 4rem);
}

.convergence-content {
    position: relative;
    max-width: 800px;
    margin: 0 auto;
}

.convergence-radial-burst {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(224, 17, 95, 0.06) 0%, transparent 70%);
    pointer-events: none;
}

.convergence-headline {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: 0.01em;
    line-height: 1.15;
    color: #E0115F;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.convergence-body {
    color: #E8DFD0;
    font-size: clamp(1.05rem, 1.9vw, 1.3rem);
    line-height: 1.8;
    margin-bottom: 1.5rem;
    position: relative;
    z-index: 2;
}

.convergence-body-secondary {
    color: #8A7E70;
    font-size: clamp(0.95rem, 1.6vw, 1.15rem);
}

.convergence-coord {
    display: inline-block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #C4A35A;
    margin-top: 2rem;
    position: relative;
    z-index: 2;
}

/* --- Grain Pulse for Convergence --- */
.section-convergence .convergence-content {
    animation: none;
}

/* --- Section: Final Coordinates --- */
.section-final {
    padding: clamp(4rem, 8vh, 8rem) clamp(1rem, 5vw, 4rem);
    background: linear-gradient(180deg, #1A0F2E 0%, #0D1B2A 100%);
    padding-bottom: clamp(8rem, 15vh, 16rem);
}

.final-grid {
    max-width: 900px;
    margin: 0 auto;
    margin-left: 8%;
}

.final-coordinates {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem 3rem;
    max-width: 800px;
    margin: clamp(4rem, 8vh, 8rem) auto 0;
    padding: 2rem;
}

.final-coord {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.65rem, 0.9vw, 0.8rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #C4A35A;
    opacity: 0.5;
    animation: coordDrift 20s ease-in-out infinite;
}

.final-coord:nth-child(2n) { animation-delay: -4s; }
.final-coord:nth-child(3n) { animation-delay: -8s; }
.final-coord:nth-child(4n) { animation-delay: -12s; }
.final-coord:nth-child(5n) { animation-delay: -16s; }

/* --- Scroll Reveal Animations --- */
.reveal-element {
    opacity: 0;
    transition: opacity 600ms cubic-bezier(0.22, 1, 0.36, 1),
                transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal-from-left {
    transform: translateX(-40px);
}

.reveal-from-right {
    transform: translateX(40px);
}

.reveal-from-below {
    transform: translateY(40px);
}

.reveal-element.revealed {
    opacity: 1;
    transform: translateX(0) translateY(0);
}

/* --- Staggered reveals for panel children --- */
.observatory-panel .section-headline {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 600ms cubic-bezier(0.22, 1, 0.36, 1) 200ms,
                transform 600ms cubic-bezier(0.22, 1, 0.36, 1) 200ms;
}

.observatory-panel .section-body {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 600ms cubic-bezier(0.22, 1, 0.36, 1) 400ms,
                transform 600ms cubic-bezier(0.22, 1, 0.36, 1) 400ms;
}

.observatory-panel .panel-metadata {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 600ms cubic-bezier(0.22, 1, 0.36, 1) 600ms,
                transform 600ms cubic-bezier(0.22, 1, 0.36, 1) 600ms;
}

.revealed .section-headline,
.revealed .section-body,
.revealed .panel-metadata {
    opacity: 1;
    transform: translateY(0);
}

/* panel-metadata inside revealed should respect its muted color */
.revealed .panel-metadata {
    opacity: 0.8;
}

/* --- Astrolabe Line Drawing Animation --- */
.astrolabe-draw {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 1.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.revealed .astrolabe-draw {
    stroke-dashoffset: 0;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .opening-content {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .opening-text {
        padding-left: 0;
    }

    .astrolabe-opening {
        order: -1;
    }

    .astrolabe-svg {
        max-width: 250px;
    }

    .observation-grid {
        grid-template-columns: 1fr;
    }

    .observation-left {
        display: none;
    }

    .entry-left,
    .entry-right {
        margin-left: auto;
        margin-right: auto;
        max-width: 95%;
    }

    .final-grid {
        margin-left: auto;
    }

    .coord-annotation {
        display: none;
    }
}

@media (max-width: 600px) {
    .observatory-panel {
        padding: clamp(1.5rem, 3vw, 2.5rem);
        clip-path: polygon(
            0% 2%,
            2% 0%,
            98% 0%,
            100% 2%,
            100% 98%,
            98% 100%,
            2% 100%,
            0% 98%
        );
    }

    .site-title {
        font-size: clamp(3rem, 12vw, 5rem);
    }

    .section-headline {
        font-size: clamp(1.8rem, 7vw, 3rem);
    }

    .convergence-headline {
        font-size: clamp(2rem, 8vw, 3.5rem);
    }
}
