/* ============================================
   yamato.quest — Cinematic Botanical Storybook
   ============================================ */

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

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

body {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.15rem);
    line-height: 1.75;
    color: #2B2B23;
    background-color: #F4EDE0;
    overflow-x: hidden;
}

/* ============================================
   Progress Vine
   ============================================ */
#progress-vine {
    position: fixed;
    left: 0;
    top: 0;
    width: 40px;
    height: 100vh;
    z-index: 100;
    pointer-events: none;
}

#vine-path {
    stroke-dasharray: 2200;
    stroke-dashoffset: 2200;
    transition: stroke-dashoffset 0.1s linear;
}

.vine-bud {
    transform-origin: center;
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.vine-bud.bloomed {
    opacity: 1;
}

/* ============================================
   Sections — General
   ============================================ */
.section {
    position: relative;
    overflow: hidden;
}

.kanji-watermark {
    position: absolute;
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 40vw;
    opacity: 0.04;
    color: #2B2B23;
    pointer-events: none;
    line-height: 1;
    z-index: 0;
    top: 50%;
    transform: translateY(-50%);
    right: -10vw;
    user-select: none;
}

/* ============================================
   Annotations
   ============================================ */
.annotation {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #8B7355;
    display: block;
    margin-bottom: 1.5rem;
}

/* ============================================
   Section Titles
   ============================================ */
.section-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(4rem, 12vw, 9rem);
    letter-spacing: -0.03em;
    line-height: 0.9;
    margin-bottom: 2rem;
}

.forest-title {
    color: #2D5A3D;
}

.meadow-title {
    color: #C7442E;
}

.twilight-title {
    color: #4A2D6B;
}

/* Vertical text */
.vertical-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.vertical-rl {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    height: clamp(14rem, 40vh, 28rem);
}

/* ============================================
   Body Text
   ============================================ */
.body-text {
    max-width: 28ch;
    color: #2B2B23;
    margin-bottom: 2rem;
}

.twilight-text {
    max-width: 36ch;
    color: #E8E2D4;
}

/* ============================================
   ACT 1: THE GATE
   ============================================ */
.gate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4rem 8vw;
    background-color: #F4EDE0;
    position: relative;
}

.gate::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: #D1D5C8;
    opacity: 0.3;
    pointer-events: none;
}

.gate-title {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2rem;
}

.gate-title .vertical-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(3rem, 8vw, 6rem);
    color: #2D5A3D;
    letter-spacing: -0.03em;
    line-height: 0.9;
    height: 60vh;
}

.gate-title .annotation {
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.gate-illustration {
    position: relative;
    z-index: 2;
    width: 50%;
    max-width: 500px;
    display: flex;
    justify-content: flex-end;
}

.gate-illustration .maple-leaf {
    width: 100%;
    height: auto;
}

.gate-scroll-hint {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    animation: bobDown 2s ease-in-out infinite;
}

@keyframes bobDown {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(10px); }
}

/* ============================================
   Forest Sections
   ============================================ */
.forest-section {
    min-height: 90vh;
    display: flex;
    align-items: center;
    gap: 4vw;
    padding: 8vh 8vw;
    background-color: #F4EDE0;
    transition: background-color 0.8s ease;
}

.left-weighted {
    flex-direction: row;
}

.left-weighted .section-content {
    margin-left: 0;
    margin-right: auto;
}

.right-weighted {
    flex-direction: row-reverse;
}

.right-weighted .section-content {
    margin-left: auto;
    margin-right: 0;
    text-align: right;
}

.right-weighted .body-text {
    margin-left: auto;
}

.right-weighted .annotation {
    text-align: right;
}

.section-content {
    flex: 1;
    max-width: 40%;
    position: relative;
    z-index: 2;
}

/* ============================================
   Specimen Plates
   ============================================ */
.specimen-plate {
    border: 1px solid #8B7355;
    padding: 2rem;
    position: relative;
    z-index: 2;
    background-color: rgba(244, 237, 224, 0.5);
    flex: 0 0 auto;
    width: clamp(220px, 30vw, 350px);
    transition: transform 0.6s ease;
}

.specimen-plate:hover {
    transform: rotate(0deg) !important;
}

.specimen-plate:hover .leaf-path {
    fill: currentColor;
}

.specimen-plate:hover .plate-label {
    color: #C7442E;
}

.plate-number {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #8B7355;
    position: absolute;
    top: 0.5rem;
    left: 0.8rem;
}

.plate-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: #8B7355;
    font-style: italic;
    display: block;
    text-align: center;
    margin-top: 0.8rem;
    transition: color 0.6s ease;
}

.specimen-svg {
    width: 100%;
    height: auto;
    display: block;
    color: #2D5A3D;
}

.leaf-path {
    transition: fill 0.6s ease;
    fill: none;
}

/* Staggered coloring on hover */
.specimen-plate:hover .leaf-path:nth-child(1) { transition-delay: 0s; }
.specimen-plate:hover .leaf-path:nth-child(2) { transition-delay: 0.05s; }
.specimen-plate:hover .leaf-path:nth-child(3) { transition-delay: 0.1s; }
.specimen-plate:hover .leaf-path:nth-child(4) { transition-delay: 0.15s; }
.specimen-plate:hover .leaf-path:nth-child(5) { transition-delay: 0.2s; }
.specimen-plate:hover .leaf-path:nth-child(6) { transition-delay: 0.25s; }
.specimen-plate:hover .leaf-path:nth-child(7) { transition-delay: 0.3s; }
.specimen-plate:hover .leaf-path:nth-child(8) { transition-delay: 0.35s; }

/* ============================================
   Vine Dividers
   ============================================ */
.vine-divider {
    height: 40vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4vw;
    background-color: #F4EDE0;
}

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

.divider-vine {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 1.2s ease;
}

.vine-divider.visible .divider-vine {
    stroke-dashoffset: 0;
}

.vine-grape {
    opacity: 0;
    transition: opacity 0.3s ease;
    transition-delay: 1.3s;
}

.vine-divider.visible .vine-grape {
    opacity: 1;
}

/* ============================================
   ACT 2: THE MEADOW
   ============================================ */
.meadow-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #F4EDE0;
    position: relative;
    transition: background-color 0.8s ease;
}

.meadow-annotation {
    text-align: center;
    margin-bottom: 1rem;
}

.meadow-title {
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
    z-index: 3;
}

.meadow-watermark {
    right: auto;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 50vw;
}

/* Mandala */
.mandala {
    position: relative;
    width: 30vw;
    height: 30vw;
    min-width: 250px;
    min-height: 250px;
    z-index: 2;
}

.mandala-leaf {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4vw;
    min-width: 35px;
    transform-origin: center bottom;
    transform: translate(-50%, -100%) rotate(calc(var(--i) * 30deg)) translateY(-12vw);
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: calc(var(--i) * 80ms);
}

.mandala.bloomed .mandala-leaf {
    transform: translate(-50%, -100%) rotate(calc(var(--i) * 30deg + 15deg)) translateY(-12vw);
}

.mandala-leaf svg {
    width: 100%;
    height: auto;
}

/* Meadow text fragments */
.meadow-fragments {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}

.fragment {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(var(--fx), var(--fy));
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    color: #8B7355;
    opacity: 0;
    transition: opacity 1s ease;
    white-space: nowrap;
}

.meadow-section.visible .fragment {
    opacity: 0.7;
}

/* ============================================
   ACT 3: TWILIGHT
   ============================================ */
.twilight-section {
    min-height: 80vh;
    display: flex;
    align-items: center;
    gap: 4vw;
    padding: 8vh 8vw;
    background-color: #4A2D6B;
    transition: background-color 0.8s ease;
}

.twilight-section .annotation {
    color: #D1D5C8;
}

.twilight-section .specimen-plate {
    border-color: #E8A4B8;
    background-color: rgba(74, 45, 107, 0.3);
}

.twilight-section .plate-number,
.twilight-section .plate-label {
    color: #D1D5C8;
}

.twilight-section .specimen-svg {
    color: #E8A4B8;
}

.twilight-section .leaf-path {
    stroke: #E8E2D4;
}

.twilight-section .specimen-plate:hover .plate-label {
    color: #E8A4B8;
}

.twilight-section .kanji-watermark {
    color: #E8E2D4;
    opacity: 0.06;
}

/* Specimen cluster */
.specimen-cluster {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    flex: 0 0 auto;
    max-width: 45%;
    z-index: 2;
}

.small-plate {
    width: clamp(140px, 15vw, 200px);
}

.tiny-specimen {
    width: 100%;
    height: auto;
}

/* ============================================
   Falling Leaves (Pure CSS)
   ============================================ */
.falling-leaves {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 1;
}

.falling-leaf {
    position: absolute;
    top: -30px;
    left: var(--x);
    width: calc(0.8rem + var(--i) * 0.04rem);
    max-width: 1.5rem;
    color: var(--color);
    opacity: calc(0.3 + var(--i) * 0.03);
    animation: fall calc(8s + var(--i) * 0.5s) linear infinite;
    animation-delay: calc(var(--i) * -0.7s);
}

.falling-leaf svg {
    width: 100%;
    height: auto;
}

@keyframes fall {
    0% {
        transform: translateY(-30px) translateX(0) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: calc(0.3 + var(--i, 0) * 0.03);
    }
    90% {
        opacity: calc(0.3 + var(--i, 0) * 0.03);
    }
    100% {
        transform: translateY(85vh) translateX(calc(sin(var(--i, 0) * 1.2) * 40px)) rotate(calc(180deg + var(--i, 0) * 20deg));
        opacity: 0;
    }
}

/* ============================================
   THE STONE (Final Section)
   ============================================ */
.stone-section {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #2B2B23;
    text-align: center;
    padding: 4rem 2rem;
}

.stone-kanji {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(8rem, 25vw, 18rem);
    color: #E8E2D4;
    line-height: 1;
    letter-spacing: -0.03em;
    margin-bottom: 2rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.2s ease, transform 1.2s ease;
}

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

.stone-text {
    font-family: 'Lora', serif;
    font-style: italic;
    color: #8B7355;
    font-size: clamp(0.9rem, 1.5vw, 1.15rem);
    opacity: 0;
    transition: opacity 1.5s ease 0.5s;
}

.stone-section.visible .stone-text {
    opacity: 1;
}

/* ============================================
   Scroll-triggered fade-up for content
   ============================================ */
.section-content,
.specimen-plate {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

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

/* Preserve plate rotations when visible */
.section.visible .specimen-plate[style*="rotate(-2deg)"] {
    transform: rotate(-2deg) translateY(0);
}
.section.visible .specimen-plate[style*="rotate(1.5deg)"] {
    transform: rotate(1.5deg) translateY(0);
}
.section.visible .specimen-plate[style*="rotate(-1deg)"] {
    transform: rotate(-1deg) translateY(0);
}
.section.visible .specimen-plate[style*="rotate(2deg)"] {
    transform: rotate(2deg) translateY(0);
}
.section.visible .specimen-plate[style*="rotate(-2.5deg)"] {
    transform: rotate(-2.5deg) translate(-20px, 10px);
}
.section.visible .specimen-plate[style*="rotate(1.8deg)"] {
    transform: rotate(1.8deg) translate(15px, -15px);
}
.section.visible .specimen-plate[style*="rotate(-0.5deg)"] {
    transform: rotate(-0.5deg) translate(-5px, 20px);
}

/* SVG path draw animation */
.gate-illustration .leaf-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 2s ease, fill 0.6s ease;
}

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

.gate.visible .leaf-path.p1 { transition-delay: 0s; }
.gate.visible .leaf-path.p2 { transition-delay: 0.15s; }
.gate.visible .leaf-path.p3 { transition-delay: 0.15s; }
.gate.visible .leaf-path.p4 { transition-delay: 0.3s; }
.gate.visible .leaf-path.p5 { transition-delay: 0.3s; }
.gate.visible .leaf-path.p6 { transition-delay: 0.45s; }
.gate.visible .leaf-path.p7 { transition-delay: 0.45s; }
.gate.visible .leaf-path.p8 { transition-delay: 0.6s; }
.gate.visible .leaf-path.p9 { transition-delay: 0.6s; }
.gate.visible .leaf-path.p10 { transition-delay: 0.75s; }
.gate.visible .leaf-path.p11 { transition-delay: 0.75s; }
.gate.visible .leaf-path.p12 { transition-delay: 0.9s; }
.gate.visible .leaf-path.p13 { transition-delay: 0.9s; }

/* Hover color-in for gate maple */
.gate-illustration:hover .leaf-path {
    fill: #2D5A3D;
    transition: fill 0.6s ease;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .forest-section,
    .twilight-section {
        flex-direction: column !important;
        padding: 6vh 6vw;
        gap: 3rem;
    }

    .section-content {
        max-width: 90%;
    }

    .right-weighted .section-content {
        text-align: left;
        margin-left: 0;
    }

    .right-weighted .body-text {
        margin-left: 0;
    }

    .right-weighted .annotation {
        text-align: left;
    }

    .specimen-plate {
        width: clamp(200px, 70vw, 300px);
    }

    .specimen-cluster {
        max-width: 90%;
    }

    .gate {
        flex-direction: column;
        padding: 4rem 6vw;
        gap: 2rem;
    }

    .gate-illustration {
        width: 80%;
    }

    .gate-title .vertical-title {
        height: 40vh;
    }

    .mandala-leaf {
        transform: translate(-50%, -100%) rotate(calc(var(--i) * 30deg)) translateY(-18vw);
    }

    .mandala.bloomed .mandala-leaf {
        transform: translate(-50%, -100%) rotate(calc(var(--i) * 30deg + 15deg)) translateY(-18vw);
    }
}
