/* ============================================
   layer-2.quest — Celestial Bathhouse Styles
   ============================================ */

/* --- CSS Variables (from DESIGN.md palette) --- */
:root {
    --deep-void: #050A1A;
    --cosmic-navy: #0D1B3E;
    --oxygen-glow: #3BF0A0;
    --nitrogen-drift: #7B2FBE;
    --high-oxygen: #E040A0;
    --water-stratum: #0D4B3E;
    --cartographer-gold: #F0C674;
    --starlight: #E8E4F0;
    --nebula-dust: #8B8BA0;
    --bubble-core: #FFFFFF;
    --dark-violet: #1A0B3E;
    --deep-violet: #2D0E5E;
    --deep-teal: #0D3B4E;

    /* Gradients */
    --aurora-sweep: linear-gradient(135deg, #3BF0A0 0%, #7B2FBE 40%, #E040A0 70%, #F0C674 100%);
    --water-depth: linear-gradient(170deg, #0D4B3E 0%, #1A0B3E 35%, #2D0E5E 65%, #0D3B4E 100%);
    --cosmic-fade: radial-gradient(ellipse at 30% 40%, #0D1B3E 0%, #050A1A 100%);
}

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

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

body {
    background: var(--deep-void);
    color: var(--starlight);
    font-family: 'Crimson Pro', serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.7;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* --- Split Screen Container --- */
#split-screen {
    display: grid;
    grid-template-columns: 1fr 4px 1fr;
    min-height: 500vh;
    position: relative;
}

/* --- Panels --- */
.panel {
    position: relative;
    overflow: hidden;
}

#cosmos-panel {
    background: var(--cosmic-fade);
    z-index: 1;
}

#water-panel {
    background: var(--water-depth);
    z-index: 1;
    position: relative;
}

/* Pulsing aurora radial overlay on water panel */
#water-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 30%, rgba(59, 240, 160, 0.08) 0%, transparent 70%);
    animation: auroraPulse 8s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes auroraPulse {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* --- Cosmos Panel Content --- */
#cosmos-content {
    position: relative;
    width: 100%;
    height: 100%;
    will-change: transform;
}

#constellation-nav {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* --- Stars --- */
.star {
    fill: var(--starlight);
    opacity: 0;
    animation: starPulse 4s ease-in-out infinite alternate;
    pointer-events: auto;
    cursor: pointer;
    transition: r 200ms ease-out;
}

.nav-star:hover {
    r: 10;
}

@keyframes starPulse {
    0% { opacity: 0.5; }
    100% { opacity: 1.0; }
}

/* --- Constellation Lines --- */
.constellation-line {
    stroke: var(--cartographer-gold);
    stroke-width: 1;
    stroke-opacity: 0.4;
    stroke-dasharray: 4 6;
    stroke-dashoffset: 0;
    animation: dataFlow 6s linear infinite;
    transition: stroke-opacity 300ms ease-out;
}

@keyframes dataFlow {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -40; }
}

/* Brighten lines when hovering a nearby star */
.constellation-group:hover .constellation-line {
    stroke-opacity: 0.8;
}

/* --- Star Labels --- */
.star-label {
    font-family: 'Caveat', cursive;
    font-size: 14px;
    fill: var(--cartographer-gold);
    opacity: 0;
    transition: opacity 300ms ease-out;
    pointer-events: none;
}

.star-label.visible {
    opacity: 1;
}

/* --- Divider --- */
#divider {
    position: relative;
    width: 4px;
    cursor: col-resize;
    z-index: 10;
    user-select: none;
    touch-action: none;
}

#divider-svg {
    position: absolute;
    top: 0;
    left: -6px;
    width: 16px;
    height: 100%;
    pointer-events: none;
}

#divider-path {
    opacity: 0;
    transition: opacity 800ms ease-out;
}

#divider-path.visible {
    opacity: 0.8;
}

#divider-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
    white-space: nowrap;
    color: var(--cartographer-gold);
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 400ms ease-out;
    pointer-events: none;
}

#divider:hover #divider-label {
    opacity: 0.6;
}

/* --- Aurora Curtain Effects --- */
.aurora-curtain {
    position: absolute;
    top: 0;
    width: 40%;
    height: 100%;
    mix-blend-mode: screen;
    opacity: 0.08;
    pointer-events: none;
    z-index: 0;
}

.aurora-green {
    left: 10%;
    background: linear-gradient(180deg, transparent 0%, #3BF0A0 50%, transparent 100%);
    animation: sway 12s ease-in-out infinite alternate;
}

.aurora-violet {
    left: 35%;
    background: linear-gradient(180deg, transparent 0%, #7B2FBE 50%, transparent 100%);
    animation: sway 15s ease-in-out infinite alternate-reverse;
}

.aurora-magenta {
    left: 60%;
    background: linear-gradient(180deg, transparent 0%, #E040A0 50%, transparent 100%);
    animation: sway 18s ease-in-out infinite alternate;
    animation-delay: -4s;
}

@keyframes sway {
    0% { transform: translateX(-20px) scaleX(0.8); }
    50% { transform: translateX(20px) scaleX(1.2); }
    100% { transform: translateX(-10px) scaleX(0.9); }
}

/* --- Water Panel Content --- */
#water-content {
    position: relative;
    width: 100%;
    z-index: 2;
}

/* --- Sections (each 100vh) --- */
.section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    position: relative;
}

.section-content {
    max-width: 540px;
    width: 100%;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms ease-out, transform 800ms ease-out;
}

.section-content.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Hero Section --- */
.hero-text {
    text-align: center;
    position: relative;
}

#hero-layer {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(3.5rem, 9vw, 8rem);
    letter-spacing: 0.02em;
    line-height: 1.05;
    background: var(--aurora-sweep);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0;
}

#hero-layer.visible {
    opacity: 1;
}

#hero-two {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(8rem, 20vw, 16rem);
    line-height: 0.85;
    color: transparent;
    -webkit-text-stroke: 2px var(--cartographer-gold);
    text-stroke: 2px var(--cartographer-gold);
    opacity: 0;
    filter: url(#hand-drawn-filter);
}

#hero-two.visible {
    opacity: 1;
}

#hero-quest {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    color: var(--cartographer-gold);
    display: block;
    opacity: 0;
}

#hero-quest.visible {
    opacity: 1;
}

/* --- Section Headings --- */
.section-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    letter-spacing: 0.02em;
    line-height: 1.15;
    color: var(--starlight);
    margin-bottom: 1.5rem;
}

/* --- Body Text --- */
.body-text {
    font-family: 'Crimson Pro', serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.7;
    letter-spacing: 0.01em;
    color: var(--starlight);
    margin-bottom: 1.2rem;
}

.body-text.light-on-dark {
    color: var(--starlight);
}

/* --- Annotation Font --- */
.annotation-font {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
    color: var(--cartographer-gold);
}

.annotation-text {
    font-family: 'Caveat', cursive;
    fill: var(--cartographer-gold);
    font-size: 12px;
    opacity: 0.6;
}

/* --- Cosmos Section 3 Inverted Text --- */
#cosmos-section3-text {
    position: absolute;
    top: calc(200vh + 10vh);
    left: 10%;
    right: 10%;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 800ms ease-out, transform 800ms ease-out;
}

#cosmos-section3-text.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Gold Annotations --- */
.gold-annotation {
    position: absolute;
    opacity: 0.6;
    pointer-events: none;
}

/* --- Hand-Drawn Diagram --- */
.hand-drawn-diagram {
    width: 100%;
    max-width: 400px;
    height: auto;
    margin: 2rem auto;
    display: block;
}

/* --- Section 4: Stratum (merged moment) --- */
.stratum-content {
    text-align: center;
    max-width: none;
}

.stratum-domain {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(2.5rem, 7vw, 6rem);
    letter-spacing: 0.02em;
    line-height: 1.05;
    background: var(--aurora-sweep);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* --- Section 5: Cartographer's Notes --- */
.notes-content {
    max-width: 580px;
}

.golden-border-frame {
    border: 1.5px solid var(--cartographer-gold);
    border-radius: 12px;
    padding: 2.5rem;
    position: relative;
    filter: url(#hand-drawn-filter);
}

.golden-border-frame::before {
    content: '';
    position: absolute;
    inset: -3px;
    border: 1px solid var(--cartographer-gold);
    border-radius: 14px;
    opacity: 0.3;
}

.notes-annotation {
    margin-top: 2rem;
    text-align: right;
}

/* --- Bubbles --- */
.bubble {
    position: absolute;
    border-radius: 50%;
    background: transparent;
    box-shadow:
        inset -4px -4px 12px rgba(59, 240, 160, 0.15),
        inset 2px 2px 8px rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(1.5px) brightness(1.05);
    -webkit-backdrop-filter: blur(1.5px) brightness(1.05);
    pointer-events: none;
    z-index: 3;
    will-change: transform, opacity;
}

.bubble::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 20%;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
}

.bubble.large::before {
    width: 5px;
    height: 5px;
}

.bubble-payload {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    clip-path: circle(50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Caveat', cursive;
    font-size: 8px;
    color: var(--starlight);
    opacity: 0.5;
    pointer-events: none;
}

/* Bubble container */
#bubble-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 3;
}

/* --- Section 4 Merge Effect --- */
#section-stratum.merged #split-screen {
    grid-template-columns: 0fr 0px 1fr;
}

body.stratum-active #cosmos-panel {
    opacity: 0;
    transition: opacity 600ms ease-out;
}

body.stratum-active #divider {
    opacity: 0;
    transition: opacity 600ms ease-out;
}

body.stratum-active #water-panel {
    position: relative;
}

body.stratum-active .aurora-curtain {
    opacity: 0.15;
}

/* --- Initial State: Everything dark --- */
body.loading #cosmos-panel {
    background: var(--deep-void);
}

body.loading #water-panel {
    background: var(--deep-void);
}

body.loading .aurora-curtain {
    opacity: 0;
}

body.loading #bubble-container {
    display: none;
}

/* --- Transition States --- */
#cosmos-panel {
    transition: background 1200ms ease-out;
}

#water-panel {
    transition: background 1500ms ease-out;
}

/* --- Constellation Groups: reveal by scroll --- */
.constellation-group {
    opacity: 0;
    transition: opacity 800ms ease-out;
}

.constellation-group.revealed {
    opacity: 1;
}

/* --- Scroll-Driven Split Ratio --- */
#split-screen {
    transition: grid-template-columns 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Responsive / Mobile --- */
@media (max-width: 768px) {
    #split-screen {
        grid-template-columns: 1fr;
        grid-template-rows: 50vh 4px 1fr;
    }

    #cosmos-panel {
        grid-row: 1;
    }

    #divider {
        width: 100%;
        height: 4px;
        cursor: row-resize;
    }

    #divider-svg {
        width: 100%;
        height: 16px;
        left: 0;
        top: -6px;
    }

    #divider-label {
        transform: translate(-50%, -50%);
    }

    #water-panel {
        grid-row: 3;
    }

    .section {
        min-height: 80vh;
        padding: 3rem 1.5rem;
    }

    #hero-two {
        -webkit-text-stroke-width: 1.5px;
    }

    #cosmos-section3-text {
        top: calc(160vh);
    }
}

@media (max-width: 480px) {
    .section {
        padding: 2rem 1rem;
    }

    .golden-border-frame {
        padding: 1.5rem;
    }
}
