/* ============================================
   annual.quest - Art Deco Tropical Sunset
   Dawn-to-Twilight Scroll Narrative
   ============================================
   Animation: Intersection Observer with a 15% threshold.
   Stagger delay: 80ms per block within the same row.
   Easing: cubic-bezier(0.16, 1, 0.3, 1)
   ============================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
    /* Palette */
    --aged-linen: #FAF3E8;
    --volcanic-sand: #2D1E0F;
    --reef-blush: #E8734A;
    --gilt-brass: #D4A843;
    --shallow-water: #3B9B8F;
    --hibiscus-fade: #C4596A;
    --evening-reef: #1A2F4A;
    --warm-cream: #F5E6D0;
    --dusk-cream: #E8D4C0;

    /* Typography */
    --font-headline: 'Poiret One', cursive;
    --font-body: 'Crimson Pro', serif;
    --font-caption: 'Josefin Sans', sans-serif;

    /* Scroll-linked background */
    --scroll-bg: #FAF3E8;

    /* Mouse tracking for hover warmth */
    --mouse-x: 50%;
    --mouse-y: 50%;
}

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

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

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    color: var(--volcanic-sand);
    background-color: var(--scroll-bg);
    overflow-x: hidden;
    position: relative;
    transition: background-color 0.3s ease;
}

/* ---------- Film Grain Overlay ---------- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.06;
    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='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    animation: grain-flicker 0.48s steps(4) infinite;
}

@keyframes grain-flicker {
    0% { background-position: 0 0; }
    25% { background-position: 1px 0; }
    50% { background-position: 0 1px; }
    75% { background-position: 1px 1px; }
    100% { background-position: 0 0; }
}

/* ---------- Deco Chevron Background Pattern ---------- */
#deco-bg-pattern {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M30 0 L60 30 L30 60 L0 30Z' fill='none' stroke='%23D4A843' stroke-width='1'/%3E%3Cpath d='M30 10 L50 30 L30 50 L10 30Z' fill='none' stroke='%23D4A843' stroke-width='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 60px 60px;
}

/* ---------- Hero Section ---------- */
.hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px;
    overflow: hidden;
    z-index: 1;
}

.hero-title {
    font-family: var(--font-headline);
    font-size: clamp(2rem, 5.5vw, 4.5rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gilt-brass);
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
}

.hero-subtitle {
    font-family: var(--font-caption);
    font-weight: 300;
    font-size: clamp(0.85rem, 1.8vw, 1.1rem);
    color: var(--reef-blush);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    position: relative;
    z-index: 2;
}

/* Hero ornaments (Art Deco corner flourishes) */
.hero-ornament {
    position: absolute;
    width: 120px;
    height: 120px;
    z-index: 1;
}

.hero-ornament.top-left {
    top: 40px;
    left: 40px;
    border-top: 2px solid var(--gilt-brass);
    border-left: 2px solid var(--gilt-brass);
    opacity: 0.4;
}

.hero-ornament.top-left::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 60px;
    height: 60px;
    border-top: 1px solid var(--gilt-brass);
    border-left: 1px solid var(--gilt-brass);
    opacity: 0.6;
}

.hero-ornament.bottom-right {
    bottom: 40px;
    right: 40px;
    border-bottom: 2px solid var(--gilt-brass);
    border-right: 2px solid var(--gilt-brass);
    opacity: 0.4;
}

.hero-ornament.bottom-right::after {
    content: '';
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 60px;
    height: 60px;
    border-bottom: 1px solid var(--gilt-brass);
    border-right: 1px solid var(--gilt-brass);
    opacity: 0.6;
}

/* Hero fish animation */
.hero-fish-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 1;
}

.hero-fish {
    position: absolute;
    width: 80px;
    height: auto;
    opacity: 0.35;
    animation: hero-fish-drift 25s linear infinite;
}

.hero-fish.moorish-idol {
    top: 40%;
    left: -100px;
    animation: hero-fish-drift 25s linear infinite, fish-bob 3s ease-in-out infinite;
}

@keyframes hero-fish-drift {
    0% { transform: translateX(-100px); }
    100% { transform: translateX(calc(100vw + 100px)); }
}

@keyframes fish-bob {
    0%, 100% { margin-top: 0; }
    50% { margin-top: -8px; }
}

/* ---------- Masonry Grid ---------- */
.masonry-grid {
    column-count: 4;
    column-gap: 20px;
    padding: 40px 60px;
    position: relative;
    z-index: 1;
}

/* ---------- Masonry Blocks ---------- */
.masonry-block {
    break-inside: avoid;
    margin-bottom: 20px;
    padding: 28px 24px;
    background: rgba(250, 243, 232, 0.7);
    border: 1px solid rgba(200, 160, 100, 0.25);
    box-shadow: 0 4px 12px rgba(45, 30, 15, 0.12);
    position: relative;
    overflow: hidden;
    transition: transform 400ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 400ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    /* Entrance animation initial state */
    opacity: 0;
    transform: translateY(30px);
}

.masonry-block.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 700ms cubic-bezier(0.16, 1, 0.3, 1),
                transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.masonry-block:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(45, 30, 15, 0.18);
}

.masonry-block.visible:hover {
    transform: translateY(-4px);
}

/* Hover warmth effect */
.masonry-block::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at var(--mouse-x) var(--mouse-y), rgba(232, 115, 74, 0.08) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 400ms ease;
    pointer-events: none;
    z-index: 0;
}

.masonry-block:hover::before {
    opacity: 1;
}

/* Block corner ornaments */
.block-corner {
    position: absolute;
    width: 24px;
    height: 24px;
    opacity: 0.3;
    z-index: 1;
}

.block-corner.tl {
    top: 6px;
    left: 6px;
    border-top: 1.5px solid var(--gilt-brass);
    border-left: 1.5px solid var(--gilt-brass);
    border-top-left-radius: 2px;
}

.block-corner.br {
    bottom: 6px;
    right: 6px;
    border-bottom: 1.5px solid var(--gilt-brass);
    border-right: 1.5px solid var(--gilt-brass);
    border-bottom-right-radius: 2px;
}

/* Block aspect ratio variations */
.masonry-block.tall {
    min-height: 320px;
}

.masonry-block.wide {
    column-span: none;
    min-height: 180px;
}

.masonry-block.narrow {
    min-height: 240px;
}

.masonry-block.square {
    min-height: 220px;
}

/* Block rounded corners for some blocks */
.masonry-block.square {
    border-radius: 8px;
}

/* ---------- Block Typography ---------- */
.block-heading {
    font-family: var(--font-headline);
    font-size: clamp(1.4rem, 3vw, 2.4rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--volcanic-sand);
    margin-bottom: 16px;
    position: relative;
    z-index: 1;
}

.block-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    color: var(--volcanic-sand);
    margin-bottom: 12px;
    position: relative;
    z-index: 1;
}

.block-body strong {
    font-weight: 600;
}

.block-caption {
    font-family: var(--font-caption);
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    color: var(--reef-blush);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: block;
    margin-top: 12px;
    position: relative;
    z-index: 1;
}

/* ---------- Block Illustrations ---------- */
.block-illustration {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}

.block-illustration svg {
    width: 100%;
    max-width: 280px;
    height: auto;
}

/* ---------- Dawn Blocks ---------- */
.dawn-block {
    background: rgba(250, 243, 232, 0.85);
}

.dawn-block .block-corner.tl,
.dawn-block .block-corner.br {
    border-color: var(--gilt-brass);
}

.dawn-block .block-caption {
    color: var(--reef-blush);
}

/* ---------- Golden Hour Blocks ---------- */
.golden-block {
    background: rgba(245, 230, 208, 0.85);
    border-color: rgba(212, 168, 67, 0.35);
}

.golden-block .block-corner.tl,
.golden-block .block-corner.br {
    border-color: var(--gilt-brass);
    opacity: 0.5;
}

.golden-block .block-heading {
    color: var(--volcanic-sand);
}

/* ---------- Dusk Blocks ---------- */
.dusk-block {
    background: rgba(232, 212, 192, 0.85);
    border-color: rgba(196, 89, 106, 0.3);
}

.dusk-block .block-corner.tl,
.dusk-block .block-corner.br {
    border-color: var(--hibiscus-fade);
    opacity: 0.45;
}

.dusk-block .block-heading {
    color: var(--volcanic-sand);
}

.dusk-block .block-caption {
    color: var(--hibiscus-fade);
}

/* ---------- Twilight Blocks ---------- */
.twilight-block {
    background: rgba(26, 47, 74, 0.9);
    border-color: rgba(212, 168, 67, 0.2);
    color: var(--aged-linen);
}

.twilight-block .block-heading {
    color: var(--gilt-brass);
}

.twilight-block .block-body {
    color: var(--aged-linen);
    opacity: 0.9;
}

.twilight-block .block-caption {
    color: var(--shallow-water);
}

.twilight-block .block-corner.tl,
.twilight-block .block-corner.br {
    border-color: var(--gilt-brass);
    opacity: 0.25;
}

/* ---------- Horizon Breaks ---------- */
.horizon-break {
    position: relative;
    width: 100%;
    min-height: 160px;
    overflow: hidden;
    z-index: 2;
    margin: 20px 0;
}

.horizon-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

#horizon-break-1 .horizon-gradient {
    background: linear-gradient(180deg,
        rgba(250, 243, 232, 0.3) 0%,
        rgba(232, 115, 74, 0.1) 30%,
        rgba(212, 168, 67, 0.15) 70%,
        rgba(245, 230, 208, 0.3) 100%
    );
}

#horizon-break-2 .horizon-gradient {
    background: linear-gradient(180deg,
        rgba(245, 230, 208, 0.3) 0%,
        rgba(196, 89, 106, 0.12) 30%,
        rgba(232, 115, 74, 0.1) 70%,
        rgba(232, 212, 192, 0.3) 100%
    );
}

#horizon-break-3 .horizon-gradient {
    background: linear-gradient(180deg,
        rgba(232, 212, 192, 0.3) 0%,
        rgba(196, 89, 106, 0.08) 30%,
        rgba(26, 47, 74, 0.15) 70%,
        rgba(26, 47, 74, 0.4) 100%
    );
}

/* Horizon fish schools */
.horizon-fish-school {
    position: relative;
    width: 100%;
    height: 120px;
    z-index: 1;
}

.horizon-fish {
    position: absolute;
    width: 50px;
    height: auto;
    opacity: 0.65;
}

/* Stagger fish positions and animations */
.hf-1 { top: 20%; left: -60px; animation: fish-swim 18s linear infinite, fish-bob 3s ease-in-out infinite; animation-delay: 0s, 0s; }
.hf-2 { top: 45%; left: -60px; animation: fish-swim 22s linear infinite, fish-bob 3.2s ease-in-out infinite; animation-delay: 2s, 0.5s; }
.hf-3 { top: 15%; left: -60px; animation: fish-swim 20s linear infinite, fish-bob 2.8s ease-in-out infinite; animation-delay: 4s, 1s; }
.hf-4 { top: 60%; left: -60px; animation: fish-swim 24s linear infinite, fish-bob 3.5s ease-in-out infinite; animation-delay: 6s, 0.3s; }
.hf-5 { top: 35%; left: -60px; animation: fish-swim 19s linear infinite, fish-bob 3.1s ease-in-out infinite; animation-delay: 8s, 0.7s; }
.hf-6 { top: 55%; left: -60px; animation: fish-swim 21s linear infinite, fish-bob 2.9s ease-in-out infinite; animation-delay: 10s, 0.2s; }

.lone-fish {
    top: 30%;
    left: -120px;
    width: 80px;
    opacity: 0.5;
    animation: fish-swim 30s linear infinite, fish-bob 4s ease-in-out infinite !important;
}

@keyframes fish-swim {
    0% { transform: translateX(-80px); }
    100% { transform: translateX(calc(100vw + 80px)); }
}

/* Deco Divider */
.deco-divider {
    position: relative;
    width: 100%;
    height: 24px;
    z-index: 2;
}

.deco-divider svg {
    width: 100%;
    height: 24px;
    display: block;
}

/* ---------- Scroll Regions ---------- */
.scroll-region {
    position: relative;
    z-index: 1;
}

#dawn-section {
    padding-bottom: 20px;
}

#golden-section {
    padding: 20px 0;
}

#dusk-section {
    padding: 20px 0;
}

#twilight-section {
    padding: 20px 0;
}

/* ---------- Ambient Fish Container ---------- */
#ambient-fish-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 500;
    overflow: hidden;
}

#ambient-fish-container .ambient-fish {
    position: absolute;
    width: 40px;
    height: auto;
    opacity: 0;
    transition: opacity 2s ease;
}

#ambient-fish-container .ambient-fish.active {
    opacity: 0.2;
}

/* ---------- Scatter Fish Container ---------- */
#scatter-fish-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 499;
    overflow: hidden;
}

.scatter-fish {
    position: absolute;
    width: 16px;
    height: 16px;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---------- Footer ---------- */
#twilight-footer {
    position: relative;
    min-height: 300px;
    background: var(--evening-reef);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    z-index: 1;
}

#star-field {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--aged-linen);
    border-radius: 50%;
    animation: star-twinkle var(--twinkle-duration, 3s) ease-in-out infinite;
    animation-delay: var(--twinkle-delay, 0s);
}

@keyframes star-twinkle {
    0%, 100% { opacity: var(--star-min-opacity, 0.2); }
    50% { opacity: var(--star-max-opacity, 0.8); }
}

.footer-content {
    position: relative;
    z-index: 1;
    text-align: center;
}

.footer-text {
    font-family: var(--font-headline);
    font-size: clamp(1.6rem, 4vw, 3rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gilt-brass);
    opacity: 0.6;
    margin-bottom: 12px;
}

.footer-caption {
    font-family: var(--font-caption);
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    color: var(--shallow-water);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.5;
}

/* ---------- Responsive: Tablet ---------- */
@media (max-width: 1024px) {
    .masonry-grid {
        column-count: 3;
        column-gap: 16px;
        padding: 30px 40px;
    }

    .hero {
        padding: 40px;
    }

    .hero-ornament {
        width: 80px;
        height: 80px;
    }

    .hero-ornament.top-left { top: 24px; left: 24px; }
    .hero-ornament.bottom-right { bottom: 24px; right: 24px; }
}

/* ---------- Responsive: Mobile ---------- */
@media (max-width: 640px) {
    .masonry-grid {
        column-count: 1;
        column-gap: 0;
        padding: 20px 16px;
    }

    /* Alternating full-width and inset blocks for rhythmic variation */
    .masonry-block:nth-child(even) {
        width: 80%;
        margin-left: auto;
        margin-right: auto;
    }

    .hero {
        padding: 30px 20px;
        min-height: 80vh;
    }

    .hero-ornament {
        width: 50px;
        height: 50px;
    }

    .hero-ornament.top-left { top: 16px; left: 16px; }
    .hero-ornament.bottom-right { bottom: 16px; right: 16px; }
    .hero-ornament.top-left::after,
    .hero-ornament.bottom-right::after {
        width: 30px;
        height: 30px;
    }

    .horizon-break {
        min-height: 120px;
    }

    .horizon-fish {
        width: 35px;
    }

    .lone-fish {
        width: 55px;
    }

    .hero-fish.moorish-idol {
        width: 55px;
    }
}

/* ---------- Utility: Grain Intensification on Hover (Block Level) ---------- */
.masonry-block:hover ~ #grain-overlay {
    /* This won't work with siblings, handled via JS instead */
}
