/* ============================================
   a6c.quest — Surreal Dreamscape
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --parchment-mist: #f5f0e8;
    --burnt-terracotta: #c4593a;
    --abyssal-teal: #1a3a4a;
    --dreamers-gold: #d4a853;
    --sandstone: #8b6f5c;
    --warm-bisque: #e8d5c0;
    --twilight-ink: #2c2c3a;
    --sage-whisper: #a8c4b8;

    --dream-depth: 0;
    --saturation: 0.7;
}

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

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

body {
    font-family: 'Lora', serif;
    color: var(--sandstone);
    background: var(--parchment-mist);
    overflow-x: hidden;
    perspective: 1200px;
    -webkit-font-smoothing: antialiased;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.04;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
}

/* --- Navigation Dots --- */
#dream-nav {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 900;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.nav-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1.5px solid var(--sandstone);
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    transform: translateX(60px);
    opacity: 0;
}

.nav-dot.visible {
    transform: translateX(0);
    opacity: 1;
}

.nav-dot.active {
    background: var(--dreamers-gold);
    border-color: var(--dreamers-gold);
    transform: translateX(0) scale(1.2);
    opacity: 1;
}

.nav-dot:hover {
    border-color: var(--dreamers-gold);
    transform: translateX(0) scale(1.3);
}

.nav-dot::after {
    content: attr(data-label);
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Anybody', sans-serif;
    font-weight: 300;
    font-size: 0.65rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--sandstone);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.nav-dot:hover::after {
    opacity: 1;
}

/* --- Dream Sections (shared) --- */
.dream-section {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* --- Section 1: The Threshold --- */
#threshold {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--parchment-mist);
    clip-path: polygon(0 0, 100% 0, 100% 93%, 0 100%);
    z-index: 10;
}

.threshold-fog {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 30% 40%, rgba(232, 213, 192, 0.6) 0%, transparent 70%),
        radial-gradient(ellipse 60% 80% at 70% 60%, rgba(168, 196, 184, 0.3) 0%, transparent 60%),
        radial-gradient(ellipse 90% 70% at 50% 50%, rgba(245, 240, 232, 0.8) 0%, transparent 80%);
    animation: fogDrift1 20s ease-in-out infinite;
}

.fog-layer-2 {
    background:
        radial-gradient(ellipse 70% 50% at 60% 30%, rgba(44, 44, 58, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 50% 70% at 20% 70%, rgba(212, 168, 83, 0.1) 0%, transparent 50%);
    animation: fogDrift2 25s ease-in-out infinite !important;
}

.fog-layer-3 {
    background:
        radial-gradient(ellipse 60% 40% at 80% 20%, rgba(168, 196, 184, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse 40% 60% at 10% 80%, rgba(232, 213, 192, 0.2) 0%, transparent 40%);
    animation: fogDrift3 30s ease-in-out infinite !important;
}

@keyframes fogDrift1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(20px, -10px) scale(1.02); }
    66% { transform: translate(-15px, 8px) scale(0.98); }
}

@keyframes fogDrift2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-25px, 15px) scale(1.03); }
}

@keyframes fogDrift3 {
    0%, 100% { transform: translate(0, 0); }
    33% { transform: translate(15px, -20px); }
    66% { transform: translate(-10px, 12px); }
}

.glyph-container {
    position: relative;
    z-index: 5;
    width: clamp(15rem, 25vw, 45rem);
}

#breathing-glyph {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 0 40px rgba(196, 89, 58, 0.15));
}

#breathing-glyph text {
    font-family: 'Bodoni Moda', serif;
    font-weight: 900;
    font-size: 180px;
    fill: var(--twilight-ink);
}

.glyph-text-a {
    transform-origin: 200px 120px;
    animation: glyphBreathe 4s ease-in-out infinite;
}

.glyph-text-6 {
    transform-origin: 300px 120px;
    animation: glyphBreathe 4s ease-in-out infinite 0.3s;
}

.glyph-text-c {
    transform-origin: 400px 120px;
    animation: glyphBreathe 4s ease-in-out infinite 0.6s;
}

/* Position the three characters side by side */
.glyph-text-a { transform: translate(-100px, 0); }
.glyph-text-6 { transform: translate(0, 0); }
.glyph-text-c { transform: translate(100px, 0); }

@keyframes glyphBreathe {
    0%, 100% {
        opacity: 0.9;
        filter: blur(0px);
        letter-spacing: 0;
    }
    50% {
        opacity: 1;
        filter: blur(0.5px);
        letter-spacing: 2px;
    }
}

.scroll-chevron {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--sandstone);
    opacity: 0.5;
    animation: chevronPulse 2.5s ease-in-out infinite;
    z-index: 5;
}

.scroll-chevron svg {
    width: 40px;
    height: 24px;
}

@keyframes chevronPulse {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.5; }
    50% { transform: translateX(-50%) translateY(8px); opacity: 0.9; }
}

/* --- Section 2: The Archive --- */
#archive {
    min-height: 150vh;
    padding: 10vh 5vw 15vh;
    background: var(--warm-bisque);
    clip-path: polygon(0 3%, 100% 0, 100% 95%, 0 100%);
    z-index: 9;
    margin-top: -7vh;
    position: relative;
}

.archive-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 8vh;
}

.bento-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 1.5rem;
    position: relative;
}

.bento-box {
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    background: var(--parchment-mist);
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.bento-box.revealed {
    opacity: 1;
    transform: translateY(0);
}

.box-1 {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    min-height: 280px;
    transform: translateY(40px) rotate(-0.5deg);
}
.box-1.revealed { transform: translateY(0) rotate(-0.5deg); }

.box-2 {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    min-height: 320px;
    margin-top: -15px;
}

.box-3 {
    grid-column: 3 / 4;
    grid-row: 1 / 3;
    min-height: 500px;
    margin-left: -10px;
}

.box-4 {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    min-height: 260px;
    margin-top: -20px;
    transform: translateY(40px) rotate(0.3deg);
}
.box-4.revealed { transform: translateY(0) rotate(0.3deg); }

.box-5 {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    min-height: 280px;
}

.box-6 {
    grid-column: 3 / 4;
    grid-row: 3 / 4;
    min-height: 200px;
    margin-top: -15px;
    margin-left: -10px;
}

/* Gradient Meshes */
.gradient-mesh {
    position: absolute;
    inset: 0;
}

.mesh-1 {
    background:
        radial-gradient(ellipse 60% 50% at 20% 30%, rgba(196, 89, 58, 0.4) 0%, transparent 60%),
        radial-gradient(ellipse 40% 60% at 80% 70%, rgba(26, 58, 74, 0.3) 0%, transparent 50%),
        radial-gradient(ellipse 70% 40% at 50% 50%, rgba(212, 168, 83, 0.25) 0%, transparent 55%),
        radial-gradient(ellipse 50% 70% at 30% 80%, rgba(168, 196, 184, 0.2) 0%, transparent 45%);
    animation: meshShift1 60s ease-in-out infinite;
}

.mesh-2 {
    background:
        radial-gradient(ellipse 50% 60% at 70% 20%, rgba(26, 58, 74, 0.35) 0%, transparent 55%),
        radial-gradient(ellipse 60% 40% at 20% 60%, rgba(196, 89, 58, 0.3) 0%, transparent 50%),
        radial-gradient(ellipse 45% 55% at 60% 80%, rgba(139, 111, 92, 0.2) 0%, transparent 45%),
        radial-gradient(ellipse 55% 45% at 40% 40%, rgba(212, 168, 83, 0.3) 0%, transparent 50%);
    animation: meshShift2 60s ease-in-out infinite;
}

.mesh-3 {
    background:
        radial-gradient(ellipse 55% 55% at 40% 30%, rgba(168, 196, 184, 0.3) 0%, transparent 50%),
        radial-gradient(ellipse 45% 65% at 70% 60%, rgba(196, 89, 58, 0.25) 0%, transparent 55%),
        radial-gradient(ellipse 65% 35% at 30% 70%, rgba(26, 58, 74, 0.2) 0%, transparent 45%),
        radial-gradient(ellipse 40% 50% at 80% 20%, rgba(212, 168, 83, 0.35) 0%, transparent 50%);
    animation: meshShift3 60s ease-in-out infinite;
}

@keyframes meshShift1 {
    0%, 100% { background-position: 0% 0%, 100% 100%, 50% 50%, 30% 80%; }
    25% { background-position: 10% 15%, 85% 90%, 60% 40%, 20% 70%; }
    50% { background-position: 20% 5%, 75% 80%, 45% 60%, 35% 85%; }
    75% { background-position: 5% 10%, 90% 95%, 55% 45%, 25% 75%; }
}

@keyframes meshShift2 {
    0%, 100% { background-position: 70% 20%, 20% 60%, 60% 80%, 40% 40%; }
    33% { background-position: 60% 30%, 30% 50%, 50% 70%, 50% 50%; }
    66% { background-position: 80% 10%, 10% 70%, 70% 90%, 30% 30%; }
}

@keyframes meshShift3 {
    0%, 100% { background-position: 40% 30%, 70% 60%, 30% 70%, 80% 20%; }
    50% { background-position: 50% 20%, 60% 70%, 40% 60%, 70% 30%; }
}

/* Cipher text */
.cipher-text {
    position: absolute;
    font-family: 'Azeret Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--sage-whisper);
    opacity: 0.4;
    bottom: 1rem;
    right: 1rem;
    z-index: 2;
}

/* Annotations */
.annotation {
    position: relative;
    z-index: 2;
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    line-height: 1.85;
    color: var(--sandstone);
    padding: 2rem;
    font-style: italic;
}

/* Dot Fields */
.dot-field {
    position: absolute;
    inset: 0;
}

#dot-field-1 {
    background-color: var(--warm-bisque);
}

#dot-field-2 {
    background-color: var(--twilight-ink);
}

/* Rotating Geometric Form */
.rotating-form {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    color: var(--sandstone);
}

.rotating-form svg {
    width: 80%;
    height: auto;
    animation: formRotate 30s linear infinite;
}

@keyframes formRotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Section 3: The Cartography --- */
#cartography {
    height: 120vh;
    background: linear-gradient(180deg, var(--warm-bisque) 0%, var(--parchment-mist) 30%, var(--parchment-mist) 70%, var(--warm-bisque) 100%);
    clip-path: polygon(0 5%, 100% 0, 100% 92%, 0 100%);
    z-index: 8;
    margin-top: -8vh;
    position: relative;
    overflow: hidden;
}

.cartography-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.cartography-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 300%;
    height: 100%;
    display: flex;
    will-change: transform;
}

.terrain-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.terrain-layer svg {
    width: 100%;
    height: 100%;
}

.terrain-watermark {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.terrain-watermark svg {
    width: 100%;
    height: 100%;
}

/* --- Section 4: The Oracle --- */
#oracle {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    clip-path: polygon(0 4%, 100% 0, 100% 96%, 0 100%);
    z-index: 7;
    margin-top: -6vh;
    overflow: hidden;
    background: var(--abyssal-teal);
}

.oracle-spiral {
    position: absolute;
    inset: -50%;
    background: conic-gradient(
        from 0deg,
        var(--abyssal-teal) 0%,
        #1e4455 15%,
        var(--dreamers-gold) 25%,
        #c49a3a 30%,
        var(--abyssal-teal) 40%,
        #1e4455 55%,
        var(--dreamers-gold) 65%,
        #c49a3a 70%,
        var(--abyssal-teal) 80%,
        #1e4455 90%,
        var(--abyssal-teal) 100%
    );
    opacity: 0.25;
    animation: spiralRotate 90s linear infinite;
    border-radius: 50%;
}

@keyframes spiralRotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.oracle-content {
    position: relative;
    z-index: 5;
    max-width: 600px;
    padding: 2rem;
    text-align: center;
}

.oracle-text {
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.85;
    color: var(--parchment-mist);
    opacity: 0;
}

.oracle-text.typing .oracle-char {
    display: inline-block;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.15s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.oracle-text.typing .oracle-char.visible {
    opacity: 1;
    transform: scale(1);
}

.oracle-text.typing .oracle-char.space {
    width: 0.3em;
}

/* --- Section 5: The Fade --- */
#fade {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    clip-path: polygon(0 6%, 100% 0, 100% 100%, 0 100%);
    z-index: 6;
    margin-top: -5vh;
    background: var(--warm-bisque);
    overflow: hidden;
}

.fade-grain {
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.09;
    mix-blend-mode: multiply;
    pointer-events: none;
}

.fade-ghosts {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.ghost {
    position: absolute;
    opacity: 0.08;
    filter: grayscale(1) blur(4px);
}

.ghost-mesh {
    width: 200px;
    height: 200px;
    top: 15%;
    left: 10%;
    border-radius: 8px;
    background:
        radial-gradient(ellipse 60% 50% at 30% 40%, rgba(196, 89, 58, 0.4) 0%, transparent 60%),
        radial-gradient(ellipse 40% 60% at 70% 60%, rgba(26, 58, 74, 0.3) 0%, transparent 50%);
}

.ghost-form {
    width: 150px;
    height: 150px;
    top: 30%;
    right: 15%;
    border: 1px solid var(--sandstone);
    border-radius: 50%;
    animation: formRotate 40s linear infinite;
}

.ghost-dots {
    width: 180px;
    height: 120px;
    bottom: 25%;
    left: 60%;
    background:
        radial-gradient(circle 2px at 20% 30%, var(--sandstone) 100%, transparent 100%),
        radial-gradient(circle 2px at 50% 50%, var(--sandstone) 100%, transparent 100%),
        radial-gradient(circle 2px at 80% 40%, var(--sandstone) 100%, transparent 100%),
        radial-gradient(circle 2px at 30% 70%, var(--sandstone) 100%, transparent 100%),
        radial-gradient(circle 2px at 70% 80%, var(--sandstone) 100%, transparent 100%);
}

.fade-glyph-container {
    position: relative;
    z-index: 5;
    width: clamp(20rem, 40vw, 50rem);
    margin-bottom: 3rem;
}

#fade-glyph {
    width: 100%;
    height: auto;
}

.fade-glyph-path {
    transition: stroke-dashoffset 5s linear;
}

.fade-glyph-path.drawing {
    stroke-dashoffset: 0;
}

.fade-ending {
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.5vw, 1.15rem);
    color: var(--abyssal-teal);
    letter-spacing: 0.1em;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1.5s ease, transform 1.5s ease;
    position: relative;
    z-index: 5;
}

.fade-ending.visible {
    opacity: 0.7;
    transform: translateY(0);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .bento-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .box-3 {
        grid-column: 1 / 3;
        grid-row: auto;
        min-height: 300px;
        margin-left: 0;
    }

    .box-6 {
        grid-column: 1 / 3;
        margin-left: 0;
    }

    #dream-nav {
        right: 1rem;
        gap: 1rem;
    }

    .nav-dot::after {
        display: none;
    }

    .glyph-container {
        width: clamp(12rem, 60vw, 20rem);
    }

    .fade-glyph-container {
        width: clamp(15rem, 70vw, 25rem);
    }

    .oracle-content {
        max-width: 90vw;
    }
}

@media (max-width: 480px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }

    .box-3, .box-6 {
        grid-column: 1;
    }

    .box-1, .box-4 {
        transform: none !important;
    }

    .box-1.revealed, .box-4.revealed {
        transform: none !important;
    }
}
