/* gabs.ai - Dark Academia meets Digital Herbalism */
/* Palette: Aged Parchment #f4efe4, Deep Loam #2c2c24, Forest Moss #3d6b4e, Sage Mist #a8b5a0, Autumn Ochre #c8943e, Library Shadow #1a1e18 */

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

html {
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: "Libre Baskerville", Georgia, serif;
    background-color: #f4efe4;
    color: #2c2c24;
    overflow-x: hidden;
    counter-reset: page-counter;
}

/* Noise texture overlay */
body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    opacity: 0.035;
    mix-blend-mode: multiply;
    pointer-events: none;
    z-index: 9999;
    background-image: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27200%27 height=%27200%27%3E%3Cfilter id=%27n%27%3E%3CfeTurbulence type=%27fractalNoise%27 baseFrequency=%270.85%27 numOctaves=%274%27 stitchTiles=%27stitch%27/%3E%3CfeColorMatrix type=%27saturate%27 values=%270%27/%3E%3C/filter%3E%3Crect width=%27100%25%27 height=%27100%25%27 filter=%27url(%23n)%27/%3E%3C/svg%3E");
    background-repeat: repeat;
}

.noise-svg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    opacity: 0.035;
    mix-blend-mode: multiply;
    pointer-events: none;
    z-index: 9998;
}

/* Running Header */
.running-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8vw;
    background-color: rgba(244, 239, 228, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    border-bottom: 1px solid #a8b5a0;
    opacity: 0;
    animation: fadeInHeader 600ms 1200ms ease-out forwards;
}

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

.header-domain {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 300;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #2c2c24;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header-page {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    color: #a8b5a0;
}

.toc-glyph {
    background: none;
    border: none;
    cursor: pointer;
    color: #3d6b4e;
    padding: 4px;
    transition: color 400ms cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
}

.toc-glyph:hover {
    color: #c8943e;
}

/* Table of Contents Overlay */
.toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(26, 30, 24, 0.97);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform 400ms ease-out;
}

.toc-overlay.active {
    transform: translateY(0);
}

.toc-content {
    position: relative;
    width: 400px;
    max-width: 90vw;
}

.toc-roots {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 450px;
    opacity: 0.3;
}

.toc-trunk, .toc-branch {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 800ms ease-out;
}

.toc-overlay.active .toc-trunk,
.toc-overlay.active .toc-branch {
    stroke-dashoffset: 0;
}

.toc-node {
    opacity: 0;
    transition: opacity 400ms ease-out 600ms;
}

.toc-overlay.active .toc-node {
    opacity: 1;
}

.toc-nav {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    z-index: 1;
}

.toc-item {
    display: flex;
    align-items: baseline;
    gap: 1.5rem;
    text-decoration: none;
    color: #f4efe4;
    transition: color 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.toc-item:hover {
    color: #c8943e;
}

.toc-numeral {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    color: #a8b5a0;
    min-width: 2rem;
}

.toc-label {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 600;
    font-size: 1.5rem;
    letter-spacing: 0.08em;
}

/* Scroll Container */
.scroll-container {
    width: 100%;
}

/* Spread - Base */
.spread {
    min-height: 100vh;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 8vw 40px;
    position: relative;
    opacity: 0;
    transition: opacity 200ms ease-in-out;
}

.spread.visible {
    opacity: 1;
}

/* Title Spread */
.spread-title {
    flex-direction: column;
    text-align: center;
}

.title-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.title-leaf {
    position: absolute;
    width: 40vh;
    height: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: gentleRotate 20s ease-in-out infinite;
}

@keyframes gentleRotate {
    0%, 100% { transform: translate(-50%, -50%) rotate(-2deg); }
    50% { transform: translate(-50%, -50%) rotate(2deg); }
}

.title-domain {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 300;
    font-size: clamp(3rem, 7vw, 6rem);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #2c2c24;
    opacity: 0;
    animation: fadeInTitle 800ms 400ms ease-out forwards;
    position: relative;
    z-index: 1;
}

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

.title-rule {
    width: 0;
    height: 1px;
    background-color: #3d6b4e;
    animation: expandRule 600ms 600ms ease-out forwards;
    position: relative;
    z-index: 1;
}

@keyframes expandRule {
    to { width: 120px; }
}

.title-subtitle {
    font-family: "Libre Baskerville", serif;
    font-style: italic;
    font-size: 1.1rem;
    color: #a8b5a0;
    opacity: 0;
    animation: fadeInTitle 600ms 800ms ease-out forwards;
    position: relative;
    z-index: 1;
}

/* Chapter Spread */
.spread-chapter {
    display: grid;
    grid-template-columns: 1fr 1px 1.1fr;
    gap: 0;
    align-items: center;
    padding: 60px 0 40px;
}

.spread-left {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8vw;
    height: 100%;
}

.leaf-morph {
    width: 100%;
    max-width: 320px;
    height: auto;
}

.gutter {
    width: 1px;
    height: 70vh;
    background-color: #a8b5a0;
    opacity: 0.5;
    align-self: center;
}

.spread-right {
    padding: 0 8vw 0 4vw;
    max-width: 100%;
    position: relative;
}

/* Marginal Notes */
.marginal-note {
    font-family: "Libre Baskerville", serif;
    font-style: italic;
    font-size: 0.75rem;
    color: #a8b5a0;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    padding-left: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.marginal-leaf {
    width: 12px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Chapter Title */
.chapter-title {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 600;
    font-size: clamp(2rem, 5vw, 4.5rem);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #2c2c24;
    margin-bottom: 2rem;
    line-height: 1.1;
}

/* Chapter Body */
.chapter-body {
    max-width: 38ch;
}

.chapter-body p {
    font-size: clamp(1rem, 1.15vw, 1.2rem);
    line-height: 1.75;
    margin-bottom: 1.5em;
    color: #2c2c24;
}

/* Drop Cap */
.drop-cap-paragraph::first-letter {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 600;
    font-size: 3.5em;
    float: left;
    line-height: 0.8;
    padding-right: 0.1em;
    padding-top: 0.05em;
    color: #c8943e;
}

/* Breathing Spread */
.spread-breathing {
    flex-direction: column;
    text-align: center;
}

.breathing-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
}

.breathing-leaf-svg {
    width: 200px;
    height: auto;
}

.breathing-quote {
    font-family: "Libre Baskerville", serif;
    font-style: italic;
    font-size: 1.3rem;
    color: #a8b5a0;
    max-width: 36ch;
    line-height: 1.8;
    margin-bottom: 1.5rem;
}

.breathing-attribution {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 300;
    font-size: 0.9rem;
    color: #a8b5a0;
    letter-spacing: 0.1em;
}

/* Colophon Spread */
.spread-colophon {
    flex-direction: column;
    text-align: center;
}

.colophon-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    position: relative;
}

.colophon-text {
    position: relative;
    z-index: 1;
}

.colophon-heading {
    font-family: "Josefin Sans", sans-serif;
    font-weight: 600;
    font-size: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #2c2c24;
    margin-bottom: 2rem;
}

.colophon-detail {
    font-family: "Libre Baskerville", serif;
    font-size: 0.9rem;
    line-height: 1.8;
    color: #a8b5a0;
    margin-bottom: 0.75rem;
    max-width: 45ch;
}

.colophon-note {
    font-family: "Libre Baskerville", serif;
    font-style: italic;
    font-size: 1rem;
    color: #3d6b4e;
    margin-top: 2rem;
}

.colophon-leaf {
    width: 200px;
    height: auto;
}

/* Breathing Circle (AI Presence) */
.breathing-circle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: radial-gradient(circle, #3d6b4e 0%, transparent 70%);
    animation: breathe 4s ease-in-out infinite;
    z-index: 50;
    opacity: 0.6;
}

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

/* Stagger animation for paragraphs */
.spread-chapter .chapter-body p {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 600ms cubic-bezier(0.4, 0, 0.2, 1), transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

.spread-chapter.visible .chapter-body p {
    opacity: 1;
    transform: translateY(0);
}

.spread-chapter.visible .chapter-body p:nth-child(1) { transition-delay: 100ms; }
.spread-chapter.visible .chapter-body p:nth-child(2) { transition-delay: 200ms; }
.spread-chapter.visible .chapter-body p:nth-child(3) { transition-delay: 300ms; }

.spread-chapter .chapter-title {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 600ms cubic-bezier(0.4, 0, 0.2, 1), transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

.spread-chapter.visible .chapter-title {
    opacity: 1;
    transform: translateY(0);
}

.spread-chapter .marginal-note {
    opacity: 0;
    transition: opacity 800ms cubic-bezier(0.4, 0, 0.2, 1);
}

.spread-chapter.visible .marginal-note {
    opacity: 1;
}

/* Leaf morph animations */
.leaf-morph {
    opacity: 0;
    transition: opacity 800ms cubic-bezier(0.4, 0, 0.2, 1);
}

.spread-chapter.visible .leaf-morph {
    opacity: 1;
}

/* Colophon specific */
.spread-colophon .colophon-text {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 800ms cubic-bezier(0.4, 0, 0.2, 1), transform 800ms cubic-bezier(0.4, 0, 0.2, 1);
}

.spread-colophon.visible .colophon-text {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile Treatment */
@media (max-width: 768px) {
    .spread-chapter {
        display: flex;
        flex-direction: column;
        padding: 60px 6vw 40px;
    }

    .gutter {
        display: none;
    }

    .spread-left {
        padding: 0;
        margin-bottom: 2rem;
    }

    .leaf-morph {
        max-width: 200px;
    }

    .spread-right {
        padding: 0;
    }

    .marginal-note {
        border-left: 2px solid #3d6b4e;
        padding-left: 1rem;
        margin-bottom: 1.5rem;
    }

    .chapter-title {
        font-size: clamp(1.5rem, 8vw, 3rem);
    }

    .title-domain {
        font-size: clamp(2rem, 10vw, 4rem);
    }

    .chapter-body {
        max-width: 100%;
    }

    .breathing-circle {
        width: 24px;
        height: 24px;
        bottom: 1rem;
        right: 1rem;
    }
}
