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

:root {
    --bg-primary: #f4f0e8;
    --bg-fog: #faf8f4;
    --text-charred: #2c2926;
    --text-stone: #3d3a36;
    --celadon: #7a9e8c;
    --persimmon: #b8785a;
    --indigo: #6b7a9e;
    --clay: #8a7e6b;
    --thread-progress: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-stone);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.85;
    overflow-x: hidden;
    position: relative;
}

/* === Crack-Glaze Texture === */
#texture-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M20 0 L25 50 L10 100 L30 150 L15 200' fill='none' stroke='%232c2926' stroke-width='0.5' opacity='0.03'/%3E%3Cpath d='M80 0 L75 60 L90 120 L70 200' fill='none' stroke='%232c2926' stroke-width='0.4' opacity='0.03'/%3E%3Cpath d='M140 0 L150 80 L130 160 L145 200' fill='none' stroke='%232c2926' stroke-width='0.5' opacity='0.03'/%3E%3Cpath d='M0 40 L60 35 L120 45 L200 38' fill='none' stroke='%232c2926' stroke-width='0.4' opacity='0.03'/%3E%3Cpath d='M0 120 L50 125 L130 115 L200 122' fill='none' stroke='%232c2926' stroke-width='0.5' opacity='0.03'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* === Particle Field === */
#particle-field {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.particle {
    position: absolute;
    opacity: 0;
    transition: opacity 4s ease;
    font-family: 'Source Serif 4', serif;
    user-select: none;
}

/* === Thread Line === */
#thread-line {
    position: fixed;
    top: 0;
    left: 12%;
    width: 4px;
    height: 100vh;
    z-index: 5;
    pointer-events: none;
}

/* === Enso Navigation (fixed left) === */
#enso-nav {
    position: fixed;
    left: calc(12% - 18px);
    top: 0;
    height: 100vh;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#enso-nav.visible {
    opacity: 1;
}

.nav-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1.5px solid var(--celadon);
    background: transparent;
    cursor: pointer;
    pointer-events: all;
    transition: all 0.4s ease;
}

.nav-dot:hover,
.nav-dot.active {
    background: var(--persimmon);
    border-color: var(--persimmon);
    transform: scale(1.15);
}

/* === Opening Moment === */
#opening {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-fog);
    position: relative;
    z-index: 2;
}

.enso-opening {
    opacity: 0;
}

.opening-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-size: clamp(4rem, 8vw, 7rem);
    color: var(--text-charred);
    letter-spacing: 0.06em;
    opacity: 0;
    transform: translateY(20px);
}

.opening-subtitle {
    font-family: 'Source Serif 4', serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    color: var(--text-stone);
    opacity: 0;
    transform: translateY(15px);
    margin-top: 0.5rem;
}

/* Animations for opening */
.opening-animate .enso-opening {
    animation: fadeIn 0.8s ease forwards;
    animation-delay: 0.6s;
}

.opening-animate .enso-opening path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: drawEnso 0.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    animation-delay: 0.6s;
}

.opening-animate .opening-title {
    animation: fadeSlideUp 1.2s ease forwards;
    animation-delay: 2s;
}

.opening-animate .opening-subtitle {
    animation: fadeSlideUp 1s ease forwards;
    animation-delay: 2.6s;
}

/* === Thought Sections === */
.thought-section {
    min-height: 90vh;
    position: relative;
    z-index: 2;
    padding: 10vh 0;
    display: flex;
    align-items: flex-start;
    padding-left: 16%;
    padding-right: 10%;
}

.thought-section .enso {
    position: absolute;
    left: calc(12% - 20px);
    top: 12vh;
}

.thought-section .enso path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke 0.4s ease;
}

.thought-section.revealed .enso path {
    animation: drawEnso 0.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    animation-delay: 0.3s;
}

.thought-section .enso:hover path {
    stroke: var(--persimmon);
}

.thought-section .enso:hover {
    cursor: pointer;
    animation: ensoPulse 0.4s ease;
}

/* Breathing spaces between sections */
.thought-section::after {
    content: '';
    display: block;
    height: 30vh;
}

/* Thought Diagrams */
.thought-diagram {
    position: absolute;
    left: calc(12% + 10px);
    top: 20vh;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 1s ease, transform 1s ease;
    width: 160px;
    height: 160px;
}

.thought-section.revealed .thought-diagram {
    opacity: 0.6;
    transform: translateY(0);
    transition-delay: 0.5s;
}

.thought-diagram svg path,
.thought-diagram svg line,
.thought-diagram svg circle {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
}

.thought-section.revealed .thought-diagram svg path,
.thought-section.revealed .thought-diagram svg line,
.thought-section.revealed .thought-diagram svg circle {
    animation: drawDiagram 1s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    animation-delay: 0.6s;
}

/* Thought Content */
.thought-content {
    margin-left: 180px;
    max-width: 520px;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    position: relative;
}

.thought-section.revealed .thought-content {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.8s;
}

.thought-number {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1vw, 1rem);
    color: var(--clay);
    position: absolute;
    left: -40px;
    top: 8px;
}

.thought-content h2 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-size: clamp(2.4rem, 5vw, 4.8rem);
    color: var(--text-charred);
    letter-spacing: 0.06em;
    margin-bottom: 1.5rem;
    line-height: 1.1;
}

.thought-content p {
    margin-bottom: 1.2rem;
    color: var(--text-stone);
}

.thought-content p.aside {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(0.85rem, 1vw, 1rem);
    color: var(--clay);
    font-style: normal;
    margin-top: 1.5rem;
}

/* === Closing Moment === */
#closing {
    height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 10vh;
    background-color: var(--bg-fog);
    position: relative;
    z-index: 2;
}

.enso-closing path {
    stroke-dasharray: 150;
    stroke-dashoffset: 150;
}

#closing.revealed .enso-closing path {
    animation: drawEnso 1s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.closing-text {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--clay);
    opacity: 0;
    margin-top: 12px;
    transition: opacity 1.2s ease;
}

#closing.revealed .closing-text {
    opacity: 0.4;
    transition-delay: 1s;
}

/* === Keyframes === */
@keyframes fadeIn {
    to { opacity: 1; }
}

@keyframes fadeSlideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

@keyframes ensoPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* === Breathing Spaces === */
.thought-section + .thought-section {
    margin-top: 5vh;
}

/* === Thread-line progress color === */
#thread-line path {
    transition: stroke 0.6s ease;
}

/* === Mobile === */
@media (max-width: 768px) {
    #thread-line {
        left: 8%;
    }

    .thought-section {
        padding-left: 10%;
        padding-right: 5%;
    }

    .thought-section .enso {
        left: calc(8% - 16px);
        width: 32px;
        height: 32px;
    }

    .thought-diagram {
        display: none;
    }

    .thought-content {
        margin-left: 24px;
    }

    .thought-number {
        left: -20px;
    }

    #enso-nav {
        left: calc(8% - 8px);
    }

    .nav-dot {
        width: 10px;
        height: 10px;
    }
}
