/* ==========================================================
   scriptgrapher.com — Coastal Botanical Studies
   ========================================================== */

/* --- CSS Custom Properties (Palette from DESIGN.md) --- */
:root {
    --cotton-paper: #f7f3ee;
    --driftwood-wash: #ede5d8;
    --deep-marine: #1b3a4b;
    --tidal-slate: #4a6670;
    --sand-gold: #c9a96e;
    --coastal-sage: #7a9e7e;
    --adriatic-blue: #2e6b8a;
    --sea-foam: #d4e8e0;
}

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--cotton-paper);
    color: var(--deep-marine);
    font-family: 'Libre Baskerville', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.78;
    overflow-x: hidden;
}

/* --- Typography --- */
.hero-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.12em;
    color: var(--deep-marine);
    line-height: 1.1;
    margin-bottom: 0.5em;
}

.hero-title.ink-pool {
    animation: inkPooling 3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    animation-delay: 1.6s;
    opacity: 0;
}

@keyframes inkPooling {
    0% {
        font-weight: 300;
        opacity: 0;
        transform: translateY(10px);
    }
    20% {
        opacity: 1;
    }
    100% {
        font-weight: 600;
        opacity: 1;
        transform: translateY(0);
    }
}

.hero-subtitle {
    font-family: 'Dancing Script', cursive;
    font-weight: 700;
    font-size: clamp(0.9rem, 2vw, 1.3rem);
    color: var(--tidal-slate);
    opacity: 0;
    animation: fadeInSubtle 0.8s ease forwards;
    animation-delay: 2.4s;
}

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

.section-heading {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    letter-spacing: 0.06em;
    color: var(--deep-marine);
    margin-bottom: 1em;
    line-height: 1.2;
}

.section-heading em {
    font-style: italic;
    font-weight: 300;
}

.plate-number {
    font-family: 'Dancing Script', cursive;
    font-weight: 700;
    font-size: clamp(0.9rem, 2vw, 1.3rem);
    color: var(--tidal-slate);
    display: block;
    margin-bottom: 0.8em;
}

.body-text {
    font-family: 'Libre Baskerville', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.78;
    color: var(--deep-marine);
    margin-bottom: 1.5em;
}

.body-text em {
    font-style: italic;
}

.pull-quote {
    background-color: var(--sea-foam);
    padding: 1.5em 2em;
    border-radius: 2px;
    margin: 2em 0;
}

/* Wave underline for key phrases */
.wave-underline {
    text-decoration: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 6'%3E%3Cpath d='M0 3 Q10 0 20 3 Q30 6 40 3' fill='none' stroke='%23c9a96e' stroke-width='1' opacity='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: bottom 2px left;
    background-size: 20px 3px;
    padding-bottom: 4px;
}

/* --- SG Monogram --- */
.sg-monogram {
    position: fixed;
    top: 2rem;
    left: 2rem;
    z-index: 100;
    display: block;
    text-decoration: none;
    transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.sg-monogram-svg {
    display: block;
}

.sg-path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: drawMonogram 2s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.sg-path:nth-child(2) {
    animation-delay: 0.5s;
}

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

/* --- Wave Navigation (Desktop) --- */
.wave-nav {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    opacity: 0;
    transition: opacity 0.6s ease;
    pointer-events: none;
}

.wave-nav.visible {
    opacity: 1;
    pointer-events: auto;
}

.wave-glyph {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transform: scale(1);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.wave-glyph.active {
    opacity: 1;
    animation: glyphPulse 2s infinite ease-in-out;
}

@keyframes glyphPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.15);
        opacity: 1;
    }
}

.wave-glyph:hover {
    transform: scale(1.2);
    opacity: 1;
}

/* --- Viewport Wave Border (Desktop) --- */
.viewport-border {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
}

.border-wave {
    position: absolute;
}

.border-top {
    top: 0;
    left: 0;
    width: 100%;
    height: 8px;
}

.border-bottom {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 8px;
}

.border-left {
    top: 0;
    left: 0;
    width: 8px;
    height: 100%;
}

.border-right {
    top: 0;
    right: 0;
    width: 8px;
    height: 100%;
}

.breathing-wave {
    animation: breatheWave 6s infinite ease-in-out;
}

.breathing-wave-v {
    animation: breatheWaveV 6s infinite ease-in-out;
}

@keyframes breatheWave {
    0%, 100% {
        d: path("M0 4 Q83 0 167 4 Q250 8 333 4 Q417 0 500 4 Q583 8 667 4 Q750 0 833 4 Q917 8 1000 4");
    }
    50% {
        d: path("M0 4 Q83 8 167 4 Q250 0 333 4 Q417 8 500 4 Q583 0 667 4 Q750 8 833 4 Q917 0 1000 4");
    }
}

@keyframes breatheWaveV {
    0%, 100% {
        d: path("M4 0 Q0 83 4 167 Q8 250 4 333 Q0 417 4 500 Q8 583 4 667 Q0 750 4 833 Q8 917 4 1000");
    }
    50% {
        d: path("M4 0 Q8 83 4 167 Q0 250 4 333 Q8 417 4 500 Q0 583 4 667 Q8 750 4 833 Q0 917 4 1000");
    }
}

/* --- Plate (Section) Layout --- */
.plate {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.plate-hero {
    background-color: var(--cotton-paper);
}

.plate-neptune {
    background-color: var(--driftwood-wash);
}

.plate-tamarisk {
    background-color: var(--cotton-paper);
}

.plate-lavender {
    background-color: var(--driftwood-wash);
}

.plate-colophon {
    min-height: 50vh;
    background-color: var(--cotton-paper);
}

/* Text-dominant plate grid: 1fr min(640px, 84vw) 1fr */
.plate-text-layout {
    display: grid;
    grid-template-columns: 1fr min(640px, 84vw) 1fr;
    width: 100%;
    padding: 4rem 2rem;
}

.plate-content {
    padding: 2rem 0;
}

/* Split plate grid: side-by-side botanical and text */
.plate-split-layout {
    display: grid;
    grid-template-columns: 1fr 20px 1fr;
    gap: 0;
    width: 100%;
    max-width: 1200px;
    padding: 4rem 2rem;
    align-items: center;
}

.plate-botanical-col {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.plate-divider-col {
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 2rem 0;
}

.stem-divider {
    height: 100%;
    min-height: 300px;
}

.plate-text-col {
    padding: 2rem 2vw;
}

.plate-text-col-first {
    order: -1;
}

/* Hero specific: content offset 38% from left */
.plate-hero .plate-content {
    position: relative;
    z-index: 2;
}

.plate-hero .plate-inner {
    align-items: center;
    min-height: 100vh;
}

/* --- Botanical Bleeds --- */
.botanical-bleed {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    pointer-events: none;
}

.botanical-right {
    right: -40px;
}

.botanical-left {
    left: -60px;
}

/* --- SVG Path Drawing Animations --- */
.botanical-draw {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    opacity: 0;
}

.botanical-draw.animate {
    animation: drawPath 4s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.botanical-draw.botanical-draw-delay-1.animate {
    animation-delay: 0.8s;
}

.botanical-draw.botanical-draw-delay-2.animate {
    animation-delay: 1.6s;
}

.botanical-draw.botanical-draw-delay-3.animate {
    animation-delay: 2.4s;
}

@keyframes drawPath {
    0% {
        stroke-dashoffset: 1000;
        opacity: 1;
    }
    1% {
        opacity: 1;
    }
    100% {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

/* Neptune grass sway */
.neptune-sway.animate {
    animation: drawPath 4s cubic-bezier(0.25, 0.1, 0.25, 1) forwards,
               neptuneSwayMotion 4s ease-in-out infinite 4s;
}

.neptune-sway.botanical-draw-delay-1.animate {
    animation: drawPath 4s cubic-bezier(0.25, 0.1, 0.25, 1) 0.8s forwards,
               neptuneSwayMotion 4s ease-in-out infinite 4.8s;
}

.neptune-sway.botanical-draw-delay-2.animate {
    animation: drawPath 4s cubic-bezier(0.25, 0.1, 0.25, 1) 1.6s forwards,
               neptuneSwayMotion 4s ease-in-out infinite 5.6s;
}

@keyframes neptuneSwayMotion {
    0%, 100% {
        transform: skewX(-2deg);
    }
    50% {
        transform: skewX(2deg);
    }
}

/* Tamarisk cascade reveal */
.tamarisk-cascade.animate {
    animation: drawPath 3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

/* Flower dots for lavender */
.flower-dot {
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1),
                opacity 0.6s ease;
}

.flower-dot.animate {
    opacity: 1;
}

/* --- Wave Section Transitions (clip-path) --- */
.plate.wave-entering {
    animation: waveReveal 800ms cubic-bezier(0.45, 0, 0.55, 1) forwards;
}

@keyframes waveReveal {
    0% {
        clip-path: polygon(0 100%, 8% 97%, 16% 100%, 25% 96%, 33% 100%, 42% 97%, 50% 100%, 58% 96%, 67% 100%, 75% 97%, 83% 100%, 92% 96%, 100% 100%, 100% 100%, 0 100%);
    }
    100% {
        clip-path: polygon(0 0%, 8% 3%, 16% 0%, 25% 4%, 33% 0%, 42% 3%, 50% 0%, 58% 4%, 67% 0%, 75% 3%, 83% 0%, 92% 4%, 100% 0%, 100% 100%, 0 100%);
    }
}

/* --- Wave Dividers --- */
.wave-divider {
    position: relative;
    z-index: 10;
    height: 24px;
    overflow: visible;
}

.breathing-wave-divider {
    animation: breatheDivider 6s infinite ease-in-out;
}

@keyframes breatheDivider {
    0%, 100% {
        d: path("M0 12 Q100 0 200 12 Q300 24 400 12 Q500 0 600 12 Q700 24 800 12 Q900 0 1000 12 Q1100 24 1200 12");
    }
    50% {
        d: path("M0 12 Q100 24 200 12 Q300 0 400 12 Q500 24 600 12 Q700 0 800 12 Q900 24 1000 12 Q1100 0 1200 12");
    }
}

/* --- Scroll-triggered Content Animations --- */
.plate-content,
.plate-text-col {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s cubic-bezier(0.25, 0.1, 0.25, 1),
                transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.plate-content.reveal,
.plate-text-col.reveal {
    opacity: 1;
    transform: translateY(0);
}

/* Hero plate content is special - starts visible after animations */
.plate-hero .plate-content {
    opacity: 1;
    transform: none;
}

/* Staggered children animation */
.plate-text-col.reveal .plate-number {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.plate-text-col.reveal .section-heading {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.12s forwards;
}

.plate-text-col.reveal .body-text:nth-of-type(1) {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.24s forwards;
}

.plate-text-col.reveal .body-text:nth-of-type(2) {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.36s forwards;
}

.plate-text-col.reveal .body-text:nth-of-type(3) {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.48s forwards;
}

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

/* Non-hero plate content children start invisible */
.plate:not(.plate-hero) .plate-text-col .plate-number,
.plate:not(.plate-hero) .plate-text-col .section-heading,
.plate:not(.plate-hero) .plate-text-col .body-text,
.plate:not(.plate-hero) .plate-content .plate-number,
.plate:not(.plate-hero) .plate-content .section-heading,
.plate:not(.plate-hero) .plate-content .body-text {
    opacity: 0;
}

.plate:not(.plate-hero) .plate-content.reveal .plate-number {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.plate:not(.plate-hero) .plate-content.reveal .section-heading {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.12s forwards;
}

.plate:not(.plate-hero) .plate-content.reveal .body-text:nth-of-type(1) {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.24s forwards;
}

.plate:not(.plate-hero) .plate-content.reveal .body-text:nth-of-type(2) {
    animation: contentFadeIn 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) 0.36s forwards;
}

/* --- Colophon --- */
.colophon-text {
    font-family: 'Libre Baskerville', serif;
    font-style: italic;
    font-size: clamp(0.9rem, 1.5vw, 1.05rem);
    line-height: 1.78;
    color: var(--tidal-slate);
    max-width: 560px;
    margin: 0 auto 2rem;
    text-align: center;
}

.colophon-sig {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: 1.5rem;
    letter-spacing: 0.3em;
    color: var(--adriatic-blue);
    text-align: center;
}

.sig-dot {
    color: var(--sand-gold);
}

/* --- Magnetic Interaction Feedback --- */
[data-magnetic] {
    transition: transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    /* Wave nav hidden on mobile */
    .wave-nav {
        display: none;
    }

    /* Viewport border hidden on mobile */
    .viewport-border {
        display: none;
    }

    /* SG monogram smaller on mobile */
    .sg-monogram {
        top: 1rem;
        left: 1rem;
    }

    .sg-monogram-svg {
        width: 44px;
        height: 44px;
    }

    /* Plates stack vertically */
    .plate-split-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 3rem 4vw;
    }

    .plate-divider-col {
        display: none;
    }

    .plate-text-col {
        padding: 0;
        order: 0;
    }

    .plate-text-col-first {
        order: 0;
    }

    .plate-botanical-col {
        max-height: 400px;
        overflow: hidden;
    }

    .plate-text-layout {
        grid-template-columns: 1fr min(640px, 92vw) 1fr;
        padding: 3rem 4vw;
    }

    /* Botanical bleeds become subtle edge decorations */
    .botanical-bleed {
        opacity: 0.4;
        transform: translateY(-50%) scale(0.7);
    }

    .botanical-right {
        right: -100px;
    }

    .botanical-left {
        left: -120px;
    }

    .hero-title {
        text-align: center;
    }

    .hero-subtitle {
        text-align: center;
    }

    .plate-content {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .botanical-bleed {
        opacity: 0.25;
    }

    .plate {
        min-height: auto;
        padding: 2rem 0;
    }

    .plate-hero {
        min-height: 100vh;
    }
}

/* --- Selection Color --- */
::selection {
    background-color: var(--sea-foam);
    color: var(--deep-marine);
}