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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    color: #2d2d2d;
    background: #f5f0eb;
    overflow-x: hidden;
}

/* === Scan Line Overlay === */
#scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        transparent 0px,
        transparent 1px,
        rgba(45,45,45,0.03) 1px,
        rgba(45,45,45,0.03) 2px
    );
    animation: scan-drift 4s linear infinite;
}

@keyframes scan-drift {
    from { background-position-y: 0; }
    to { background-position-y: 4px; }
}

/* === Particle Container === */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
}

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    pointer-events: none;
    transition: transform 2s ease-out, opacity 2s ease-out;
}

/* === Section Base === */
.section {
    min-height: 100vh;
    display: flex;
    position: relative;
    overflow: hidden;
}

.section--parchment {
    background: #f5f0eb;
}

.section--linen {
    background: #ede6dd;
}

/* Gradient blend between sections */
.section::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
    height: 80px;
    z-index: 1;
}

.section--linen::before {
    background: linear-gradient(to bottom, #f5f0eb, #ede6dd);
}

.section--parchment + .section--parchment::before {
    display: none;
}

#section3::before {
    background: linear-gradient(to bottom, #ede6dd, #f5f0eb);
}

/* === Section Title === */
.section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: -0.02em;
    color: #2d2d2d;
}

/* === Section 1: Hello, I am an Idiot === */
#section1 {
    flex-direction: column;
    justify-content: space-between;
}

.s1-title {
    padding: 12vh 8vw;
    z-index: 2;
}

.glitch-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(4rem, 12vw, 8rem);
    letter-spacing: -0.02em;
    color: #2d2d2d;
    animation: glitch-shift 8s step-end infinite;
}

@keyframes glitch-shift {
    0%, 98.5% { transform: translate(0, 0); }
    98.5%, 99.5% { transform: translate(2px, 1px); }
    99.5%, 100% { transform: translate(0, 0); }
}

.s1-vine {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.vine-main {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: draw-vine 3s ease-in-out forwards;
}

@keyframes draw-vine {
    to { stroke-dashoffset: 0; }
}

.vine-leaf {
    opacity: 0;
    animation: fade-leaf 0.4s ease-out forwards;
}

.vine-leaf:nth-child(1) { animation-delay: 3.0s; }
.vine-leaf:nth-child(2) { animation-delay: 3.2s; }
.vine-leaf:nth-child(3) { animation-delay: 3.4s; }
.vine-leaf:nth-child(4) { animation-delay: 3.6s; }
.vine-leaf:nth-child(5) { animation-delay: 3.8s; }
.vine-leaf:nth-child(6) { animation-delay: 4.0s; }
.vine-leaf:nth-child(7) { animation-delay: 4.2s; }
.vine-leaf:nth-child(8) { animation-delay: 4.4s; }
.vine-leaf:nth-child(9) { animation-delay: 4.6s; }
.vine-leaf:nth-child(10) { animation-delay: 4.8s; }
.vine-leaf:nth-child(11) { animation-delay: 5.0s; }
.vine-leaf:nth-child(12) { animation-delay: 5.2s; }

@keyframes fade-leaf {
    to { opacity: 1; }
}

.s1-intro {
    margin-left: auto;
    margin-top: auto;
    padding: 8vh 8vw;
    z-index: 2;
}

.s1-intro p {
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 1.1rem;
    line-height: 1.8;
    max-width: 38ch;
    color: #2d2d2d;
}

/* === Section 2: Things I Got Wrong Today === */
#section2 {
    flex-direction: column;
    padding: 10vh 8vw;
}

.s2-columns {
    display: flex;
    gap: 5%;
    width: 100%;
    z-index: 2;
}

.s2-left {
    flex: 0 0 60%;
}

.s2-left .section-title {
    margin-bottom: 2rem;
}

.s2-right {
    flex: 0 0 35%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fern-svg {
    width: 100%;
    max-width: 200px;
    height: auto;
}

.fern-frond {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}

.fern-frond.drawn {
    animation: draw-frond 1.5s ease-in-out forwards;
}

@keyframes draw-frond {
    to { stroke-dashoffset: 0; }
}

/* Error Cards */
.error-card {
    position: relative;
    background: #f5f0eb;
    border: 1px solid #a8b5a0;
    border-radius: 12px;
    padding: 1.5rem 2rem;
    margin-bottom: 1rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.error-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.leaf-sprig {
    position: absolute;
    top: -8px;
    right: 12px;
}

.error-card__title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #2d2d2d;
}

.error-card__body {
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #7a7267;
}

/* === Section 3: The Garden of Mistakes === */
#section3 {
    flex-direction: column;
    position: relative;
    min-height: 120vh;
}

.s3-label {
    padding: 8vh 8vw;
    z-index: 2;
}

.thought-island {
    position: absolute;
    max-width: 220px;
    padding: 1.2rem 1.4rem;
    border: 1px dashed #a8b5a0;
    border-radius: 16px;
    z-index: 2;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.thought-island.visible {
    opacity: 1;
    transform: translateY(0);
}

.thought-island p {
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 0.9rem;
    line-height: 1.65;
    color: #2d2d2d;
}

/* Spore background elements */
.spore {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #b8a9d4;
    opacity: 0.2;
    animation: float-spore 30s ease-in-out infinite alternate;
    z-index: 0;
}

.spore:nth-child(odd) {
    background: #6ecfcf;
    animation-duration: 25s;
}

.spore:nth-child(3n) {
    background: #e8a0b4;
    width: 5px;
    height: 5px;
    animation-duration: 35s;
}

@keyframes float-spore {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

.s3-flower {
    position: absolute;
    bottom: 8vh;
    right: 8vw;
    width: 60px;
    height: 60px;
    z-index: 2;
}

.flower-petal {
    stroke-dasharray: 80;
    stroke-dashoffset: 80;
}

.flower-petal.drawn {
    animation: draw-petal 0.6s ease-out forwards;
}

.flower-center {
    opacity: 0;
}

.flower-center.drawn {
    animation: fade-leaf 0.5s ease-out 0.5s forwards;
}

@keyframes draw-petal {
    to { stroke-dashoffset: 0; }
}

/* === Section 4: Still Learning === */
#section4 {
    flex-direction: column;
}

.s4-content {
    flex: 0 0 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8vh 8vw;
}

.s4-text {
    text-align: center;
}

.s4-farewell {
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 1.2rem;
    line-height: 1.7;
    max-width: 32ch;
    margin: 0 auto 1.5rem;
    color: #2d2d2d;
}

.s4-system {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    color: #7a7267;
}

.s4-bloom-flower {
    width: 80px;
    height: 80px;
    margin-top: 2rem;
}

.bloom-petal {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
}

.bloom-petal.drawn {
    animation: draw-bloom 3s ease-in-out forwards;
}

@keyframes draw-bloom {
    to { stroke-dashoffset: 0; }
}

.bloom-center {
    opacity: 0;
}

.bloom-center.drawn {
    animation: fade-leaf 0.5s ease-out 2.8s forwards;
}

.s4-void {
    flex: 0 0 50%;
    background: #f5f0eb;
}

/* Electric Cyan accent: #00f0ff used in glitch moments */
/* === Glitch Effects === */
.glitch-clone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.glitch-clone--teal {
    transform: translateX(3px);
    filter: hue-rotate(140deg) saturate(3);
    opacity: 0.6;
}

.glitch-clone--rose {
    transform: translateX(-3px);
    filter: hue-rotate(300deg) saturate(3);
    opacity: 0.6;
}

/* Bloom flower glitch */
.s4-bloom-flower.glitched {
    animation: bloom-glitch 100ms step-end;
}

@keyframes bloom-glitch {
    0% { transform: translateX(4px); filter: hue-rotate(0deg); }
    50% { transform: translateX(-4px); filter: hue-rotate(200deg); }
    100% { transform: translateX(0); filter: none; }
}

/* === Responsive === */
@media (max-width: 768px) {
    .s2-columns {
        flex-direction: column;
    }

    .s2-left {
        flex: 1;
    }

    .s2-right {
        flex: 1;
        margin-top: 2rem;
    }

    .thought-island {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        max-width: 100%;
        margin: 1rem 8vw;
    }

    #section3 {
        min-height: auto;
        padding-bottom: 10vh;
    }

    .s3-flower {
        position: relative;
        bottom: auto;
        right: auto;
        margin: 2rem auto;
        display: block;
    }
}
