/* === Custom Properties & Animations === */
@property --scroll-progress {
    syntax: '<number>';
    initial-value: 0;
    inherits: true;
}

@property --text-weight {
    syntax: '<number>';
    initial-value: 340;
    inherits: true;
}

:root {
    --shingle-mist: #e8e4dc;
    --kelp-dark: #1e2a25;
    --driftwood-ink: #2c3530;
    --tidal-gray: #6b7d75;
    --sea-lavender: #7b6d99;
    --verdigris: #5b8a72;
    --horizon-amber: #c49a5c;
    --tide-foam: #f4f1eb;
    --surface-light: #d8dcd6;
    --surface-mid: #c8d4cc;
    --elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --scroll-progress: 0;
    --text-weight: 340;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: var(--text-weight);
    color: var(--driftwood-ink);
    line-height: 1.75;
    letter-spacing: 0.015em;
    background: linear-gradient(175deg, #e8e4dc 0%, #d8dcd6 40%, #c8d4cc 70%, #1e2a25 100%);
    min-height: 500vh;
    overflow-x: hidden;
}

/* === Quest Path (Left Margin Navigation) === */
.quest-path {
    position: fixed;
    left: 20px;
    top: 0;
    width: 40px;
    height: 100vh;
    z-index: 100;
    opacity: 0.7;
}

.quest-line {
    stroke-dasharray: 2200;
    stroke-dashoffset: 2200;
    transition: stroke-dashoffset 0.1s linear;
}

.leaf-waypoint {
    opacity: 0;
    transition: opacity 0.6s ease;
}

/* === Chapter: The Shore (Hero) === */
.chapter-shore {
    height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--kelp-dark);
    position: relative;
}

.horizon-line {
    width: 0%;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--horizon-amber) 30%, var(--horizon-amber) 70%, transparent 100%);
    animation: horizonExpand 1.5s cubic-bezier(0.22, 1, 0.36, 1) 0.6s forwards;
    margin-bottom: 2rem;
}

@keyframes horizonExpand {
    to { width: 60%; }
}

.domain-title {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-weight: 300;
    font-size: clamp(2.4rem, 5vw, 4.5rem);
    color: var(--shingle-mist);
    opacity: 0;
    animation: titleReveal 1.2s var(--smooth) 2.1s forwards;
}

@keyframes titleReveal {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero-leaf {
    margin-top: 2rem;
    opacity: 0;
    animation: fadeIn 0.8s ease 2.8s forwards;
}

.hero-leaf path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: drawLeaf 2s ease-in-out 3s forwards;
}

@keyframes drawLeaf {
    to { stroke-dashoffset: 0; }
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.scroll-arrow {
    position: absolute;
    bottom: 3rem;
    opacity: 0;
    animation: fadeIn 0.5s ease 4s forwards, arrowBounce 2s ease-in-out 4s infinite;
}

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

/* === Chapter General Styles === */
.chapter {
    position: relative;
    min-height: 100vh;
    padding: 6rem 2rem;
}

.chapter-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(0.7rem, 1vw + 0.2rem, 0.85rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--tidal-gray);
    display: block;
    margin-bottom: 1rem;
}

.chapter-heading {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-weight: 300;
    font-size: clamp(2.8rem, 5vw + 1rem, 6rem);
    color: var(--driftwood-ink);
    margin-bottom: 2rem;
    opacity: 0;
    transition: opacity 0.8s ease, transform 0.8s var(--elastic), font-weight 1.2s var(--smooth);
}

.heading-left {
    transform: translateX(-80px);
}

.heading-right {
    transform: translateX(80px);
}

.chapter-heading.visible {
    opacity: 1;
    transform: translateX(0);
    font-weight: 600;
}

.text-block p {
    font-size: clamp(1rem, 1.5vw + 0.4rem, 1.25rem);
    max-width: 60ch;
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s var(--elastic);
}

.text-block p.visible {
    opacity: 1;
    transform: translateY(0);
}

/* === Wave Dividers === */
.wave-divider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
}

.wave-divider svg {
    width: 100%;
    height: 100%;
}

/* === Chapter: The Finding === */
.chapter-finding {
    display: grid;
    grid-template-columns: 60px 1fr 1fr 1fr 1fr 1fr 1fr 1fr 60px;
    gap: 1rem;
    align-items: center;
}

.finding-content {
    grid-column: 2 / 5;
    grid-row: 1;
}

.chapter-finding .wave-divider {
    grid-column: 1 / -1;
}

.compass-rose {
    grid-column: 5 / 8;
    grid-row: 1;
    width: 280px;
    height: 280px;
    position: relative;
    justify-self: center;
    opacity: 0;
    transform: scale(0.8) rotate(-10deg);
    transition: opacity 1s ease, transform 1s var(--elastic);
}

.compass-rose.visible {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.compass-outer-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px solid var(--tidal-gray);
    box-shadow: 0 0 0 8px rgba(107,125,117,0.1), 0 0 0 16px rgba(107,125,117,0.05);
}

.compass-inner-ring {
    position: absolute;
    inset: 40px;
    border-radius: 50%;
    border: 1px solid var(--verdigris);
}

.compass-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    border-radius: 50%;
    background: var(--horizon-amber);
}

.compass-cardinal {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    color: var(--tidal-gray);
    position: absolute;
}

.compass-n { top: 20px; left: 50%; transform: translateX(-50%); }
.compass-e { right: 20px; top: 50%; transform: translateY(-50%); }
.compass-s { bottom: 20px; left: 50%; transform: translateX(-50%); }
.compass-w { left: 20px; top: 50%; transform: translateY(-50%); }

.compass-leaves {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.compass-leaves path {
    stroke-dasharray: 40;
    stroke-dashoffset: 40;
    transition: stroke-dashoffset 2s ease-in-out;
}

.compass-rose.visible .compass-leaves path {
    stroke-dashoffset: 0;
}

/* === Chapter: The Artifact === */
.chapter-artifact {
    display: grid;
    grid-template-columns: 60px 1fr 1fr 1fr 1fr 1fr 1fr 1fr 60px;
    gap: 1rem;
    align-items: center;
}

.artifact-content {
    grid-column: 5 / 8;
    grid-row: 1;
}

.chapter-artifact .wave-divider {
    grid-column: 1 / -1;
}

.tide-calculator {
    grid-column: 2 / 5;
    grid-row: 1;
    width: 300px;
    height: 200px;
    position: relative;
    justify-self: center;
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s ease, transform 0.8s var(--elastic);
}

.tide-calculator.visible {
    opacity: 1;
    transform: translateY(0);
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
    padding: 20px;
}

.calc-tube {
    border-radius: 50%;
    border: 1.5px solid var(--verdigris);
    background: radial-gradient(circle at 40% 40%, rgba(91,138,114,0.15), transparent);
    box-shadow: 0 0 8px rgba(91,138,114,0.2) inset;
}

.calc-circuit {
    border: 1px solid var(--tidal-gray);
    border-radius: 2px;
    opacity: 0.6;
}

.calc-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--tidal-gray);
    position: absolute;
}

.calc-label-1 { bottom: 5px; left: 30px; }
.calc-label-2 { bottom: 5px; left: 50%; transform: translateX(-50%); }
.calc-label-3 { bottom: 5px; right: 30px; }

.calc-leaves {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    height: 50%;
    pointer-events: none;
}

.calc-leaves path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 2s ease-in-out;
}

.tide-calculator.visible .calc-leaves path {
    stroke-dashoffset: 0;
}

/* === Chapter: The Message === */
.chapter-message {
    display: grid;
    grid-template-columns: 60px 1fr 1fr 1fr 1fr 1fr 1fr 1fr 60px;
    gap: 1rem;
    align-items: center;
}

.message-content {
    grid-column: 2 / 5;
    grid-row: 1;
}

.chapter-message .wave-divider {
    grid-column: 1 / -1;
}

.message-bottle {
    grid-column: 5 / 8;
    grid-row: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-self: center;
    opacity: 0;
    transform: rotate(-5deg) translateY(30px);
    transition: opacity 1s ease, transform 1s var(--elastic);
}

.message-bottle.visible {
    opacity: 1;
    transform: rotate(0deg) translateY(0);
}

.bottle-svg {
    width: 120px;
    height: 280px;
}

.bottle-outline {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 2.5s ease-in-out;
}

.message-bottle.visible .bottle-outline {
    stroke-dashoffset: 0;
}

.bottle-neck-leaf, .bottle-neck-leaf-2 {
    stroke-dasharray: 30;
    stroke-dashoffset: 30;
    transition: stroke-dashoffset 1.5s ease-in-out 1s;
}

.message-bottle.visible .bottle-neck-leaf,
.message-bottle.visible .bottle-neck-leaf-2 {
    stroke-dashoffset: 0;
}

.bottle-scroll {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    max-height: 120px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 1s ease 2s;
}

.message-bottle.visible .bottle-scroll {
    opacity: 1;
}

.scroll-text {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 0.6rem;
    color: var(--sea-lavender);
    line-height: 1.5;
    text-align: center;
    animation: scrollText 8s linear infinite;
}

@keyframes scrollText {
    0% { transform: translateY(100%); }
    100% { transform: translateY(-100%); }
}

/* === Chapter: The Horizon (Final) === */
.chapter-horizon {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--kelp-dark);
}

.leaf-cluster {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1s ease, transform 1s var(--elastic);
    margin-bottom: 3rem;
}

.leaf-cluster.visible {
    opacity: 1;
    transform: translateY(0);
}

.leaf-cluster path {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    transition: stroke-dashoffset 2s ease-in-out;
}

.leaf-cluster.visible path {
    stroke-dashoffset: 0;
}

.final-question {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-weight: 300;
    font-size: clamp(1.8rem, 4vw + 0.5rem, 3.5rem);
    color: var(--shingle-mist);
    text-align: center;
    max-width: 70ch;
    padding: 0 2rem;
    opacity: 0;
    transition: opacity 2s ease, color 3s ease;
}

.final-question.visible {
    opacity: 1;
    color: var(--horizon-amber);
}

.final-leaf {
    margin-top: 3rem;
    opacity: 0;
    transition: opacity 1s ease 1s, transform 1.5s var(--elastic) 1s;
    transform: scale(1);
}

.final-leaf.visible {
    opacity: 1;
    transform: scale(1.5);
}

.final-leaf-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 2s ease-in-out 1.5s, fill 1s ease 3s;
    fill: transparent;
}

.final-leaf.visible .final-leaf-path {
    stroke-dashoffset: 0;
    fill: rgba(91, 138, 114, 0.3);
}

.final-leaf-vein, .final-leaf-vein-l, .final-leaf-vein-r {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 1.5s ease-in-out 2s;
}

.final-leaf.visible .final-leaf-vein,
.final-leaf.visible .final-leaf-vein-l,
.final-leaf.visible .final-leaf-vein-r {
    stroke-dashoffset: 0;
}

/* === Responsive === */
@media (max-width: 768px) {
    .chapter-finding,
    .chapter-artifact,
    .chapter-message {
        display: flex;
        flex-direction: column;
        gap: 3rem;
    }

    .compass-rose,
    .tide-calculator,
    .message-bottle {
        width: 200px;
        height: 200px;
    }

    .quest-path {
        display: none;
    }

    .chapter-content {
        padding: 0 1rem;
    }
}

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

    .compass-rose,
    .tide-calculator {
        width: 160px;
        height: 160px;
    }
}
