/* =========================================
   THE HORIZON
   ========================================= */
.horizon-section {
    display: flex; flex-direction: column; height: 100vh;
    background-color: #000; position: relative;
    z-index: 10; overflow: hidden;
}

.rain-canvas {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%; z-index: 1; pointer-events: none;
    opacity: 0; transition: opacity 0.2s ease;
}

/* ================= THE SKY ================= */
.horizon-sky {
    height: 50%; width: 100%;
    position: relative; display: flex; justify-content: center;
    z-index: 2; overflow: hidden;
}

.sky-gradient-overlay, .ocean-gradient-overlay, .horizon-sun {
    will-change: opacity; transform: translateZ(0);
}

.sky-gradient-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to bottom, transparent 0%, rgba(20, 20, 25, 0.8) 100%);
    opacity: 0; transition: opacity 0.2s ease; 
}

/* ================= THE CONSTELLATION ================= */
.constellation-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 3; 
    pointer-events: none; 
}

.op-star {
    position: absolute;
    width: 8px; height: 8px;
    background: 
        radial-gradient(circle at center, #fff 1px, transparent 2px),
        linear-gradient(90deg, transparent 40%, rgba(255,255,255,0.8) 50%, transparent 60%),
        linear-gradient(0deg, transparent 40%, rgba(255,255,255,0.8) 50%, transparent 60%);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    opacity: 0; 
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.4));
    transition: transform 0.3s ease, filter 0.3s ease, opacity 0.2s ease;
}

.op-star::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 40px; height: 40px;
    background: transparent;
    border-radius: 50%;
}

.op-star:hover {
    transform: scale(1.6);
    filter: drop-shadow(0 0 6px var(--theme-accent, #fff)) drop-shadow(0 0 12px var(--theme-accent, #fff));
}

/* BASE TWINKLE: Runs when active, automatically stops if clicked/flashing */
.horizon-section.is-active-zone .op-star:not(.is-pulsing):not(.is-flaring):not(.is-blinking) {
    animation: starBaseTwinkle 3s infinite alternate ease-in-out;
}

/* Stagger the base twinkle so they don't blink in unison */
.op-star[data-star="1"] { animation-delay: 0.1s; }
.op-star[data-star="2"] { animation-delay: 0.5s; }
.op-star[data-star="3"] { animation-delay: 0.2s; }
.op-star[data-star="4"] { animation-delay: 0.7s; }
.op-star[data-star="5"] { animation-delay: 0.4s; }
.op-star[data-star="6"] { animation-delay: 0.8s; }
.op-star[data-star="7"] { animation-delay: 0.3s; }

@keyframes starBaseTwinkle {
    0%   { opacity: 0.3; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1.2); filter: drop-shadow(0 0 6px rgba(255,255,255,0.8)); }
}

/* STATE 1: Continuous Twinkle */
.op-star.is-blinking { animation: starBlink 0.5s infinite alternate ease-in-out; }

/* STATE 2: Wrong Sequence (Dull Flash) */
.op-star.is-pulsing { animation: starPulseOnce 0.6s ease-out forwards; }

/* STATE 3: Immediate Click Feedback (Explosive Flare) */
.op-star.is-flaring { animation: starFlareClick 0.3s ease-out forwards; }

@keyframes starBlink {
    0%   { transform: scale(1); filter: drop-shadow(0 0 2px rgba(255,255,255,0.4)); }
    100% { transform: scale(1.6); filter: drop-shadow(0 0 8px var(--theme-accent, #fff)); }
}

@keyframes starPulseOnce {
    0%   { transform: scale(2); filter: drop-shadow(0 0 10px #fff); }
    100% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(255,255,255,0.4)); }
}

@keyframes starFlareClick {
    0%   { transform: scale(1); background-color: transparent; }
    50%  { transform: scale(3); filter: drop-shadow(0 0 15px #fff) drop-shadow(0 0 30px var(--theme-accent, #fff)); background-color: #fff; }
    100% { transform: scale(1.6); background-color: transparent; }
}

/* ================= THE SUN ================= */
.horizon-sun {
    position: absolute; bottom: -60px; left: 50%; 
    transform: translateX(-50%) translateY(80px); 
    width: 120px; height: 120px; border-radius: 50%;
    background: var(--theme-accent);
    box-shadow: 0 0 40px var(--theme-accent);
    opacity: 0; 
    transition: opacity 0.2s ease, transform 0.2s ease; 
    cursor: pointer;
}

@keyframes sunPulse {
    0%   { box-shadow: 0 0 40px var(--theme-accent), 0 0 60px transparent; }
    100% { box-shadow: 0 0 60px var(--theme-accent), 0 0 120px var(--theme-accent); }
}

/* ================= THE OCEAN ================= */
.horizon-ocean {
    height: 50%; width: 100%; position: relative;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 3; display: flex; flex-direction: column; align-items: center;
}

.ocean-gradient-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to bottom, rgba(10, 10, 15, 0.8) 0%, transparent 100%);
    opacity: 0; transition: opacity 0.2s ease;
}

.ocean-reflection {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding-top: 10px; width: 120px; opacity: 0; transition: opacity 0.2s ease; z-index: 10;
}

.ripple {
    height: 3px; background: var(--theme-accent);
    animation: gentleWave 3s infinite alternate ease-in-out;
}
.ripple-1 { width: 100%; opacity: 0.8; animation-delay: 0.0s; }
.ripple-2 { width: 85%;  opacity: 0.5; animation-delay: 0.2s; }
.ripple-3 { width: 65%;  opacity: 0.3; animation-delay: 0.4s; }
.ripple-4 { width: 40%;  opacity: 0.1; animation-delay: 0.6s; }

/* ================= OCEAN CONTENT ================= */
.ocean-content {
    margin-top: auto; margin-bottom: 50px;
    display: flex; flex-direction: column; align-items: center; gap: 20px;
    z-index: 10;
}

.ocean-title {
    font-family: 'Montserrat', sans-serif; font-size: 14px;
    font-weight: 300; letter-spacing: 12px; color: rgba(255, 255, 255, 0.6);
}

.ocean-links { display: flex; gap: 60px; }

.ocean-link {
    font-family: monospace; font-size: 12px; letter-spacing: 4px;
    color: rgba(255, 255, 255, 0.3); text-decoration: none; transition: all 0.4s ease;
}
.ocean-link:hover {
    color: var(--theme-accent, #c68a95); text-shadow: 0 0 10px var(--theme-accent, #c68a95);
    transform: translateY(-2px);
}

.cinematic-subtitles { text-align: center; margin-bottom: 20px; }

.sub-line, .ocean-title, .ocean-links {
    opacity: 0; 
    transition: opacity 0.2s ease; 
}
.sub-line {
    font-family: monospace; font-size: 11px; letter-spacing: 5px;
    color: rgba(255, 255, 255, 0.4); margin-bottom: 12px;
}

/* =========================================
   ANIMATION STATE 1: FAST (Subsequent Scrolls)
   ========================================= */
.horizon-section.is-active-zone .sky-gradient-overlay,
.horizon-section.is-active-zone .ocean-gradient-overlay { opacity: 1; transition: opacity 1.5s ease; }
.horizon-section.is-active-zone .ocean-reflection { opacity: 1; transition: opacity 1.5s ease; }
.horizon-section.is-active-zone .rain-canvas { opacity: 1; transition: opacity 1.5s ease; }

.horizon-section.is-active-zone .op-star { opacity: 1; transition: opacity 2s ease 1s; }

.horizon-section.is-active-zone .horizon-sun { 
    transform: translateX(-50%) translateY(0); 
    opacity: 0.8; 
    transition: opacity 1.5s ease, transform 1.5s cubic-bezier(0.2, 0.8, 0.2, 1); 
    animation: sunPulse 4s infinite alternate ease-in-out 1.5s; 
}

.horizon-section.is-active-zone .sub-line,
.horizon-section.is-active-zone .ocean-title,
.horizon-section.is-active-zone .ocean-links {
    opacity: 1; transition: opacity 1.5s ease;
}

/* =========================================
   ANIMATION STATE 2: CINEMATIC (First Scroll Only)
   ========================================= */
.horizon-section.is-cinematic.is-active-zone .sky-gradient-overlay,
.horizon-section.is-cinematic.is-active-zone .ocean-gradient-overlay { transition: opacity 4s ease 0.5s; }
.horizon-section.is-cinematic.is-active-zone .ocean-reflection { transition: opacity 2s ease 1s; }
.horizon-section.is-cinematic.is-active-zone .rain-canvas { transition: opacity 3s ease 1s; }

.horizon-section.is-cinematic.is-active-zone .op-star { transition: opacity 4s ease 2.5s; }

.horizon-section.is-cinematic.is-active-zone .horizon-sun { 
    transition: opacity 2s ease 0.5s, transform 2s cubic-bezier(0.2, 0.8, 0.2, 1) 0.5s; 
}

.horizon-section.is-cinematic.is-active-zone .sub-line:nth-child(1) { transition: opacity 2s ease 3.5s; }
.horizon-section.is-cinematic.is-active-zone .sub-line:nth-child(2) { transition: opacity 2s ease 5.0s; }
.horizon-section.is-cinematic.is-active-zone .ocean-title { transition: opacity 2s ease 7.0s; }
.horizon-section.is-cinematic.is-active-zone .ocean-links { transition: opacity 2s ease 8.5s; }

/* =========================================
   ANIMATION STATE 3: THE SUNSET CLICK
   ========================================= */
.horizon-section.is-cycling .horizon-sun {
    transform: translateX(-50%) translateY(80px) !important; 
    opacity: 0 !important;
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.4, 0, 0.2, 1) !important;
}
.horizon-section.is-cycling .ocean-reflection {
    opacity: 0 !important;
    transition: opacity 0.4s ease !important;
}

/* =========================================
   GEAR 5: DOM AWAKENING
   ========================================= */

/* 1. The Windup: Pull the slingshot back */
body.gear-5-windup {
    transition: transform 2s cubic-bezier(0.5, 0, 0.2, 1);
    transform: scale(0.95) perspective(1000px) rotateX(2deg) translateY(-10px);
    overflow: hidden !important; 
}

/* 2. The Domain Expansion (The White Sun) */
body.gear-5-awakening {
    /* Hijack the Chroma engine: Forces the Sun, Ripples, and Stars to pure white! */
    --theme-accent: #ffffff !important; 
    animation: pageRubberBounce 1.5s cubic-bezier(0.28, 0.84, 0.42, 1) forwards;
    overflow: hidden !important;
}

/* 3. Broken Gravity: The rain falls UPWARDS */
body.gear-5-awakening .rain-canvas {
    transform: scaleY(-1); 
    transform-origin: center center;
}

body.gear-5-awakening .sub-line { animation: elementSquish 1.2s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.05s; }
body.gear-5-awakening .ocean-title { animation: elementSquish 1.4s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.15s; }
body.gear-5-awakening .ocean-links { animation: elementSquish 1.3s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.25s; }
body.gear-5-awakening .ripple { animation: elementSquish 1.6s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.1s; }
body.gear-5-awakening .op-star { animation: elementSquish 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards 0s !important; }

body.gear-5-awakening .horizon-sun {
    animation: sunSquish 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.1s !important;
}

/* --- KEYFRAMES --- */

@keyframes pageRubberBounce {
    0%   { transform: scale(0.95) perspective(1000px) rotateX(2deg) translateY(-10px); }
    20%  { transform: scale(1.04) skewX(-2deg) translateY(10px); } 
    40%  { transform: scale(0.98) skewX(1deg) translateY(-5px); }
    60%  { transform: scale(1.01) skewX(-0.5deg) translateY(2px); }
    100% { transform: scale(1) skewX(0deg) translateY(0); }
}

@keyframes elementSquish {
    0%   { transform: scale(1) translateY(0) skewX(0); }
    20%  { transform: scale(1.3, 0.7) translateY(15px) skewX(5deg); } 
    40%  { transform: scale(0.8, 1.2) translateY(-10px) skewX(-3deg); } 
    60%  { transform: scale(1.1, 0.9) translateY(4px) skewX(1deg); }
    80%  { transform: scale(0.95, 1.05) translateY(-2px) skewX(0); }
    100% { transform: scale(1) translateY(0) skewX(0); }
}

@keyframes sunSquish {
    0%   { transform: translateX(-50%) scale(1) translateY(0); }
    20%  { transform: translateX(-50%) scale(1.4, 0.6) translateY(20px); } 
    40%  { transform: translateX(-50%) scale(0.8, 1.2) translateY(-15px); }
    60%  { transform: translateX(-50%) scale(1.1, 0.9) translateY(5px); }
    80%  { transform: translateX(-50%) scale(0.95, 1.05) translateY(-2px); }
    100% { transform: translateX(-50%) scale(1) translateY(0); }
}

/* =========================================
   GEAR 5: DOM AWAKENING (STAGE 2 - MID BOUNCE)
   ========================================= */

body.gear-5-mid-bounce .sub-line { animation: elementSquishMid 1.2s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.05s; }
body.gear-5-mid-bounce .ocean-title { animation: elementSquishMid 1.4s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.15s; }
body.gear-5-mid-bounce .ocean-links { animation: elementSquishMid 1.3s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.25s; }
body.gear-5-mid-bounce .ripple { animation: elementSquishMid 1.6s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.1s; }
body.gear-5-mid-bounce .op-star { animation: elementSquishMid 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards 0s !important; }

body.gear-5-mid-bounce .horizon-sun {
    animation: sunSquishMid 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.1s !important;
}

@keyframes elementSquishMid {
    0%   { transform: scale(1) translateY(0) skewX(0); }
    20%  { transform: scale(1.3, 0.7) translateY(15px) skewX(5deg); } 
    40%  { transform: scale(0.8, 1.2) translateY(-10px) skewX(-3deg); } 
    60%  { transform: scale(1.1, 0.9) translateY(4px) skewX(1deg); }
    80%  { transform: scale(0.95, 1.05) translateY(-2px) skewX(0); }
    100% { transform: scale(1) translateY(0) skewX(0); }
}

@keyframes sunSquishMid {
    0%   { transform: translateX(-50%) scale(1) translateY(0); }
    20%  { transform: translateX(-50%) scale(1.4, 0.6) translateY(20px); } 
    40%  { transform: translateX(-50%) scale(0.8, 1.2) translateY(-15px); }
    60%  { transform: translateX(-50%) scale(1.1, 0.9) translateY(5px); }
    80%  { transform: translateX(-50%) scale(0.95, 1.05) translateY(-2px); }
    100% { transform: translateX(-50%) scale(1) translateY(0); }
}

/* =========================================
   GEAR 5: DOM AWAKENING (PHASE 2 - AFTERSHOCK)
   ========================================= */

/* 1. The internal elements bounce again (Page stays still) */
body.gear-5-aftershock .sub-line { animation: elementSquishAgain 1.2s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.05s; }
body.gear-5-aftershock .ocean-title { animation: elementSquishAgain 1.4s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.15s; }
body.gear-5-aftershock .ocean-links { animation: elementSquishAgain 1.3s cubic-bezier(0.25, 1, 0.5, 1) forwards 0.25s; }
body.gear-5-aftershock .op-star { animation: elementSquishAgain 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards 0s !important; }

body.gear-5-aftershock .horizon-sun {
    animation: sunLaunch 1.5s ease-out forwards 0.1s !important;
}

body.gear-5-aftershock .ocean-reflection {
    animation: rippleVanish 0.3s ease-out forwards;
}

/* --- AFTERSHOCK KEYFRAMES --- */

/* Duplicate of elementSquish to force the browser to restart the animation smoothly */
@keyframes elementSquishAgain {
    0%   { transform: scale(1) translateY(0) skewX(0); }
    20%  { transform: scale(1.3, 0.7) translateY(15px) skewX(5deg); } 
    40%  { transform: scale(0.8, 1.2) translateY(-10px) skewX(-3deg); } 
    60%  { transform: scale(1.1, 0.9) translateY(4px) skewX(1deg); }
    80%  { transform: scale(0.95, 1.05) translateY(-2px) skewX(0); }
    100% { transform: scale(1) translateY(0) skewX(0); }
}

@keyframes sunLaunch {
    0%   { transform: translateX(-50%) scale(1) translateY(0); }
    10%  { transform: translateX(-50%) scale(1.2, 0.8) translateY(15px); } 
    30%  { transform: translateX(-50%) scale(0.8, 1.2) translateY(-15px); } 
    80%  { transform: translateX(-50%) scale(1.2) translateY(-22vh); } 
    100% { transform: translateX(-50%) scale(1.2) translateY(-22vh); } 
}

@keyframes rippleVanish {
    0%   { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.5); visibility: hidden; } 
}

/* ================= THE SILHOUETTE ================= */
.nika-silhouette {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    width: 130%; 
    height: auto;
    pointer-events: none; 
}

/* Triggered during the Phase 2 Aftershock */
body.gear-5-aftershock .nika-silhouette {
    animation: 
        nikaPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards 1.2s,
        nikaSway 4s ease-in-out infinite 1.7s;
}

/* --- SILHOUETTE KEYFRAMES --- */

/* The Rubbery Reveal */
@keyframes nikaPop {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0) rotate(-20deg); }
    50%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2) rotate(10deg); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

/* The "Don Don Da Da" Sway */
@keyframes nikaSway {
    0%   { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
    25%  { transform: translate(-50%, -52%) scale(1.02) rotate(3deg); }
    50%  { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
    75%  { transform: translate(-50%, -48%) scale(0.98) rotate(-3deg); }
    100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

/* =========================================
   GEAR 5: DOM AWAKENING (STAGE 4 - THE FINALE)
   ========================================= */

/* 1. THE LAUGH VIBRATION: Ocean and Stars shake violently with the drums */
body.gear-5-finale .horizon-ocean,
body.gear-5-finale .op-star {
    animation: finaleShake 0.35s cubic-bezier(0.25, 1, 0.5, 1) infinite !important;
}

body.gear-5-finale .sub-line,
body.gear-5-finale .ocean-title,
body.gear-5-finale .ocean-links {
    animation: cleanBounceDrop 0.8s cubic-bezier(0.5, -0.5, 0.2, 1) forwards;
}

/* Stagger the drops slightly from top to bottom so it looks like a wave hit them */
body.gear-5-finale .sub-line:nth-child(1) { animation-delay: 0s; }
body.gear-5-finale .sub-line:nth-child(2) { animation-delay: 0.1s; }
body.gear-5-finale .ocean-title { animation-delay: 0.2s; }
body.gear-5-finale .ocean-links { animation-delay: 0.3s; }

.nika-message {
    position: absolute;
    top: 40%; 
    left: 50%;
    transform: translate(-50%, -10%);
    font-family: 'Montserrat', sans-serif;
    font-size: 18px;
    letter-spacing: 15px;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
}

body.gear-5-finale .nika-message {
    animation: messageRise 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards 1s;
}

/* --- FINALE KEYFRAMES --- */

@keyframes finaleShake {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(8px); } 
}

@keyframes cleanBounceDrop {
    0%   { transform: translateY(0); opacity: 1; }
    30%  { transform: translateY(-30px); opacity: 1; } 
    100% { transform: translateY(150px); opacity: 0; } 
}

@keyframes messageRise {
    0%   { opacity: 0; transform: translate(-50%, 20px); }
    100% { opacity: 1; transform: translate(-50%, -50%); }
}

/* =========================================
   GEAR 5: POST-AWAKENING PERMANENCE (RELOAD STATE)
   ========================================= */

/* Ignore the global theme tape, force Nika elements to be white! */
body.gear-5-awakening #uplink-master,
body.gear-5-mid-bounce #uplink-master,
body.gear-5-aftershock #uplink-master,
body.gear-5-finale #uplink-master,
body.nika-permanence #uplink-master {
    --theme-accent: #ffffff !important; 
}

/* 1. Force the Sun into the sky (Size matched to Stage 3) and make unclickable */
body.nika-permanence .horizon-section.is-active-zone .horizon-sun {
    transform: translateX(-50%) translateY(-22vh) scale(1.2) !important;
    animation: none !important;
    opacity: 1 !important;
    pointer-events: none !important; 
    background: #ffffff !important; 
    box-shadow: 0 0 40px #ffffff !important;
}

/* 2. Force the Silhouette to be visible and swaying */
body.nika-permanence .nika-silhouette {
    opacity: 1 !important;
    animation: nikaSway 4s ease-in-out infinite !important;
}

body.nika-permanence .ocean-reflection {
    display: none !important;
}

/* Hide the temporary Nika Message HTML element since JS swapped the main title text */
body.nika-permanence .nika-message {
    display: none !important;
}

/* =========================================
   GEAR 5: MOBILE OPTIMIZATIONS
   ========================================= */
@media screen and (max-width: 768px) {
    /* 1. Shrink the base Sun so the 1.2x scale doesn't consume the whole screen */
    .horizon-sun {
        width: 80px !important; 
        height: 80px !important; 
        bottom: -40px !important; 
    }
    
    .ocean-reflection {
        width: 80px !important; 
    }

    /* 2. Prevent the cinematic "THE JOURNEY CONTINUES" from overflowing the screen */
    .nika-message {
        font-size: 12px !important;
        letter-spacing: 6px !important;
        top: 45% !important; 
    }

    /* 3. Override the inline JS style for the permanent title on reload */
    body.nika-permanence .ocean-title {
        font-size: 12px !important;
        letter-spacing: 6px !important;
    }

    .ocean-content {
        margin-bottom: 30px !important;
        gap: 15px !important;
    }

    .ocean-links {
        gap: 15px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
}