/* ============================================
   storiographer.com — Midnight Herbarium
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --deep-bg: #0b1628;
    --primary-bg: #132238;
    --tertiary-bg: #1c3254;
    --text-parchment: #e8dcc8;
    --text-faded: #c4b8a4;
    --accent-teal: #3d8b7a;
    --accent-rose: #a86e5c;
    --accent-steel: #8fa7c4;
    --highlight-gold: #c9a84c;
    --spine-rule: #2a3f5f;
    --grid-size: 48px;
    --golden-narrow: 38.2%;
    --golden-wide: 61.8%;
    --content-max: 38em;
    --transition-color: 300ms ease-in-out;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--deep-bg);
    color: var(--text-faded);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    line-height: 1.72;
    overflow-x: hidden;
    opacity: 0;
    transform: translateY(8px);
    animation: fadeInSite 1.2s ease-out 0.1s forwards;
}

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

/* --- Mixed-Media Texture Layer --- */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent var(--grid-size),
            rgba(42, 63, 95, 0.06) var(--grid-size),
            rgba(42, 63, 95, 0.06) calc(var(--grid-size) + 1px)
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent var(--grid-size),
            rgba(42, 63, 95, 0.06) var(--grid-size),
            rgba(42, 63, 95, 0.06) calc(var(--grid-size) + 1px)
        );
}

/* Paper grain noise texture */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    mix-blend-mode: overlay;
}

/* --- Grid Texture Background --- */
.grid-texture {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent calc(var(--grid-size) - 1px),
            rgba(42, 63, 95, 0.08) calc(var(--grid-size) - 1px),
            rgba(42, 63, 95, 0.08) var(--grid-size)
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent calc(var(--grid-size) - 1px),
            rgba(42, 63, 95, 0.08) calc(var(--grid-size) - 1px),
            rgba(42, 63, 95, 0.08) var(--grid-size)
        );
    mask-image: radial-gradient(ellipse 60% 70% at 50% 50%, transparent 30%, black 80%);
    -webkit-mask-image: radial-gradient(ellipse 60% 70% at 50% 50%, transparent 30%, black 80%);
}

/* Foxing spots */
.grid-texture::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle 8px at 15% 25%, rgba(168, 110, 92, 0.04) 0%, transparent 100%),
        radial-gradient(circle 12px at 78% 42%, rgba(168, 110, 92, 0.03) 0%, transparent 100%),
        radial-gradient(circle 6px at 42% 68%, rgba(168, 110, 92, 0.05) 0%, transparent 100%),
        radial-gradient(circle 10px at 88% 15%, rgba(168, 110, 92, 0.03) 0%, transparent 100%),
        radial-gradient(circle 7px at 25% 82%, rgba(168, 110, 92, 0.04) 0%, transparent 100%),
        radial-gradient(circle 9px at 65% 90%, rgba(168, 110, 92, 0.03) 0%, transparent 100%),
        radial-gradient(circle 5px at 50% 10%, rgba(168, 110, 92, 0.04) 0%, transparent 100%);
}

/* --- Leaf Navigation Glyph --- */
#nav-leaf {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 1000;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    transition: transform var(--transition-color);
}

#nav-leaf:hover .leaf-stroke {
    stroke: var(--accent-teal);
    transition: stroke var(--transition-color);
}

#nav-leaf:hover {
    transform: rotate(15deg);
}

.leaf-stroke {
    transition: stroke var(--transition-color);
}

/* --- Table of Contents Overlay --- */
.toc-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(11, 22, 40, 0.96);
    transform: translateX(-100%);
    transition: transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.toc-content {
    max-width: 600px;
    width: 90%;
}

.toc-title {
    font-family: 'Rokkitt', 'Rockwell', serif;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3rem);
    color: var(--text-parchment);
    margin-bottom: 2rem;
    letter-spacing: 0.01em;
}

.toc-list {
    list-style: none;
}

.toc-item {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 0.8rem 0;
    cursor: pointer;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 400ms ease-out, transform 400ms ease-out, color var(--transition-color);
    border-bottom: 1px solid rgba(42, 63, 95, 0.2);
}

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

.toc-overlay.active .toc-item:nth-child(1) { transition-delay: 80ms; }
.toc-overlay.active .toc-item:nth-child(2) { transition-delay: 160ms; }
.toc-overlay.active .toc-item:nth-child(3) { transition-delay: 240ms; }
.toc-overlay.active .toc-item:nth-child(4) { transition-delay: 320ms; }
.toc-overlay.active .toc-item:nth-child(5) { transition-delay: 400ms; }
.toc-overlay.active .toc-item:nth-child(6) { transition-delay: 480ms; }

.toc-item span {
    font-family: 'Rokkitt', 'Rockwell', serif;
    font-weight: 400;
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    color: var(--text-faded);
    transition: color var(--transition-color);
}

.toc-item:hover span {
    color: var(--accent-teal);
}

.toc-item:hover .toc-thumb path,
.toc-item:hover .toc-thumb circle {
    stroke: var(--accent-teal);
    transition: stroke var(--transition-color);
}

.toc-thumb path,
.toc-thumb circle {
    transition: stroke var(--transition-color);
}

/* --- Main Content --- */
.main-content {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* --- Herbarium Spine --- */
.herbarium-spine {
    position: fixed;
    top: 0;
    bottom: 0;
    left: calc((100vw - 1200px) / 2 + 2rem + var(--golden-narrow));
    width: 1px;
    background: rgba(42, 63, 95, 0.3);
    z-index: 1;
    pointer-events: none;
}

@media (max-width: 1200px) {
    .herbarium-spine {
        left: calc(2rem + var(--golden-narrow));
    }
}

/* --- Content Sections --- */
.content-section {
    display: flex;
    gap: 2rem;
    min-height: 80vh;
    padding: 12vh 0;
    position: relative;
}

/* --- Margin Garden (Left Column) --- */
.margin-garden {
    flex: 0 0 var(--golden-narrow);
    max-width: var(--golden-narrow);
    position: relative;
    padding-right: 2rem;
}

.margin-annotation {
    position: sticky;
    top: 30vh;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
    margin-bottom: 3rem;
}

.margin-annotation.visible {
    opacity: 1;
    transform: translateX(0);
}

.margin-annotation.faded {
    opacity: 0.3;
}

.margin-label {
    display: block;
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-steel);
    margin-bottom: 0.5rem;
}

.margin-caption {
    display: block;
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.04em;
    color: #6b7f9a;
    line-height: 1.5;
}

.margin-pullquote {
    font-family: 'Rokkitt', 'Rockwell', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--accent-steel);
    border-left: 3px solid #2a5a8c;
    padding-left: 1rem;
    line-height: 1.5;
}

.margin-sketch {
    display: block;
    margin-top: 0.5rem;
}

/* --- Content Column (Right Column) --- */
.content-column {
    flex: 1;
    min-width: 0;
}

.content-block {
    margin-bottom: 2.5rem;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 600ms ease-out, transform 600ms ease-out;
}

.content-block.revealed {
    opacity: 1;
    transform: translateX(0);
}

/* Stagger Pattern */
.stagger-flush {
    padding-left: 0;
}

.stagger-indent-1 {
    padding-left: 4vw;
}

.stagger-indent-2 {
    padding-left: 8vw;
}

/* --- Typography --- */
.section-title {
    font-family: 'Rokkitt', 'Rockwell', serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    color: var(--text-parchment);
    letter-spacing: 0.01em;
    line-height: 1.2;
    margin-bottom: 1.5rem;
}

.body-text {
    max-width: var(--content-max);
    margin-bottom: 1.2rem;
    color: var(--text-faded);
}

.body-text:last-child {
    margin-bottom: 0;
}

/* --- Story Link --- */
.story-link {
    display: inline-block;
    margin-top: 1.5rem;
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 300;
    font-size: clamp(0.85rem, 1.4vw, 1rem);
    letter-spacing: 0.04em;
    color: var(--accent-teal);
    text-decoration: none;
    border-bottom: 1px solid rgba(61, 139, 122, 0.3);
    padding-bottom: 2px;
    transition: color var(--transition-color), border-color var(--transition-color);
}

.story-link:hover {
    color: var(--text-parchment);
    border-color: var(--text-parchment);
}

/* --- Botanical Plates --- */
.botanical-plate {
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8vh 0;
    position: relative;
}

.botanical-plate-final {
    min-height: 30vh;
    padding: 6vh 0 12vh;
}

.plate-illustration {
    width: 100%;
    max-width: 400px;
    height: auto;
}

.plate-small {
    max-width: 200px;
}

.plate-caption {
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(0.75rem, 1.2vw, 0.9rem);
    letter-spacing: 0.02em;
    color: rgba(143, 167, 196, 0.6);
    margin-top: 1.5rem;
    text-align: center;
}

/* --- SVG Path Drawing Animation --- */
.draw-path {
    stroke-dasharray: var(--path-length, 1000);
    stroke-dashoffset: var(--path-length, 1000);
    transition: stroke-dashoffset 2.5s cubic-bezier(0.65, 0, 0.35, 1);
}

.draw-path.drawn {
    stroke-dashoffset: 0;
}

/* --- Stem Dividers --- */
.stem-divider {
    display: flex;
    justify-content: center;
    padding: 4vh 0;
}

.stem-divider svg {
    width: 60%;
    max-width: 400px;
    height: auto;
}

/* --- Hover Specimens --- */
.hover-specimens {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

.hover-specimen {
    position: absolute;
    opacity: 0;
    transition: opacity 250ms ease-out;
    pointer-events: none;
}

.hover-specimen.visible {
    opacity: 1;
}

.hover-specimen.fading {
    opacity: 0;
    transition: opacity 400ms ease-out;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .content-section {
        flex-direction: column;
        gap: 1rem;
        padding: 8vh 0;
    }

    .margin-garden {
        flex: none;
        max-width: 100%;
        padding-right: 0;
        padding-bottom: 1rem;
    }

    .margin-annotation {
        position: relative;
        top: auto;
        transform: none;
        opacity: 0.7;
    }

    .margin-annotation.visible {
        transform: none;
    }

    .herbarium-spine {
        display: none;
    }

    .stagger-indent-1 {
        padding-left: 2vw;
    }

    .stagger-indent-2 {
        padding-left: 4vw;
    }

    .botanical-plate {
        min-height: 40vh;
    }

    .main-content {
        padding: 0 1.2rem;
    }

    #nav-leaf {
        top: 16px;
        left: 16px;
    }
}

@media (max-width: 480px) {
    .section-title {
        font-size: clamp(1.8rem, 8vw, 2.4rem);
    }

    .stagger-indent-1,
    .stagger-indent-2 {
        padding-left: 0;
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    body {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .content-block {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .margin-annotation {
        opacity: 0.7;
        transform: none;
        transition: none;
    }

    .draw-path {
        stroke-dasharray: none;
        stroke-dashoffset: 0;
        transition: none;
    }

    .toc-overlay {
        transition: none;
    }

    .toc-item {
        opacity: 1;
        transform: none;
        transition: none;
    }
}
