/* ============================================
   munju.club — Pastoral-Technological Watercolor
   Naturalist's Field Journal
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Palette */
    --deep-canopy: #1a3a2a;
    --forest-fern: #2d5a3d;
    --spring-moss: #4a7c59;
    --burnt-umber-wash: #8b6240;
    --raw-sienna-light: #c49a5c;
    --vellum-white: #f5f0e6;
    --aged-folio: #ede4d3;
    --deep-bark: #2a1f1a;
    --lichen-silver: #a8b8a0;
    --foxglove: #c4857a;
    --deep-pine: #2d5a3d;
    --moss-ink: #5a7a5e;

    /* Typography */
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Lora', Georgia, serif;
    --font-annotation: 'Caveat', cursive;
    --font-tech: 'IBM Plex Mono', 'Courier New', monospace;

    /* Spacing */
    --spine-width: 48px;
    --column-gap: 24px;
}

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

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

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.05rem);
    line-height: 1.72;
    color: var(--deep-bark);
    background-color: var(--vellum-white);
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 1px,
            rgba(139, 98, 64, 0.02) 1px,
            rgba(139, 98, 64, 0.02) 2px
        ),
        radial-gradient(
            ellipse at center,
            transparent 30%,
            var(--aged-folio) 100%
        );
    overflow-x: hidden;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

/* --- SVG Filters (hidden) --- */
svg[style*="position:absolute"] {
    pointer-events: none;
}

/* --- Floating Spores Canvas --- */
#sporeCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 100;
}

/* --- Circuit Traces SVG Overlay --- */
.circuit-traces-svg {
    position: fixed;
    top: 0;
    left: var(--spine-width);
    width: calc(100vw - var(--spine-width));
    height: 100vh;
    pointer-events: none;
    z-index: 5;
}

/* ============================================
   JOURNAL COVER — Opening Sequence
   ============================================ */
.journal-cover {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--deep-canopy);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transform-origin: left center;
    transition: transform 1400ms cubic-bezier(0.4, 0, 0.2, 1), opacity 400ms ease;
    will-change: transform;
}

.journal-cover.opening {
    transform: perspective(1200px) rotateY(-85deg);
}

.journal-cover.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.cover-texture {
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            90deg,
            rgba(255, 255, 255, 0.02) 0px,
            transparent 1px,
            transparent 16px
        ),
        repeating-linear-gradient(
            0deg,
            rgba(255, 255, 255, 0.01) 0px,
            transparent 1px,
            transparent 12px
        );
    pointer-events: none;
}

.cover-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.2rem, 4vw, 3.5rem);
    color: var(--aged-folio);
    letter-spacing: 0.04em;
    text-shadow:
        1px 1px 0 rgba(255, 255, 255, 0.1),
        -1px -1px 0 rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 1;
}

.cover-subtitle {
    font-family: var(--font-annotation);
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    color: var(--lichen-silver);
    margin-top: 16px;
    opacity: 0.7;
    letter-spacing: 0.02em;
}

/* ============================================
   FOLIO SPINE — Left Navigation
   ============================================ */
.folio-spine {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--spine-width);
    height: 100vh;
    background-color: var(--deep-canopy);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 48px;
    transform: translateX(-100%);
    transition: transform 500ms ease-out;
    will-change: transform;
}

.folio-spine.visible {
    transform: translateX(0);
}

.spine-texture {
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04) 0px,
        transparent 1px,
        transparent 8px
    );
    pointer-events: none;
}

.spine-label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--lichen-silver);
    text-decoration: none;
    letter-spacing: 0.03em;
    padding: 8px 4px;
    position: relative;
    transition: color 300ms ease;
    cursor: pointer;
}

.spine-label::before {
    content: '';
    position: absolute;
    top: 0;
    right: -40px;
    width: 120px;
    height: 100%;
    background: linear-gradient(to right, rgba(74, 124, 89, 0.15), transparent);
    opacity: 0;
    transition: opacity 600ms ease-out;
    pointer-events: none;
    transform: rotate(180deg);
}

.spine-label:hover {
    color: var(--vellum-white);
}

.spine-label:hover::before {
    opacity: 1;
}

/* ============================================
   PAGE SURFACE — Main Content Area
   ============================================ */
.page-surface {
    margin-left: var(--spine-width);
    padding: 60px 40px 80px;
    max-width: calc(100vw - var(--spine-width));
    opacity: 0;
    transition: opacity 800ms ease;
}

.page-surface.visible {
    opacity: 1;
}

/* ============================================
   JOURNAL SECTIONS
   ============================================ */
.journal-section {
    margin-bottom: 80px;
    position: relative;
}

.section-title-wrap {
    text-align: center;
    margin-bottom: 32px;
    position: relative;
}

.section-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--deep-canopy);
    letter-spacing: 0.02em;
    line-height: 1.15;
    display: inline-block;
    position: relative;
}

/* Typewriter cursor */
.typewriter-title .typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background-color: var(--deep-pine);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursorBlink 530ms step-end infinite;
}

.typewriter-cursor.hidden {
    animation: none;
    opacity: 0;
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* --- Watercolor Wash Dividers --- */
.wash-divider {
    width: 100%;
    height: 12px;
    margin-bottom: 40px;
    display: block;
}

/* ============================================
   MASONRY GRID
   ============================================ */
.masonry-grid {
    column-count: 3;
    column-gap: var(--column-gap);
}

@media (max-width: 1024px) {
    .masonry-grid {
        column-count: 2;
    }
}

@media (max-width: 640px) {
    .masonry-grid {
        column-count: 1;
    }
}

/* ============================================
   ENTRY CARDS
   ============================================ */
.entry-card {
    break-inside: avoid;
    display: inline-block;
    width: 100%;
    margin-bottom: var(--column-gap);
    padding: 20px 24px 28px 24px;
    background-color: var(--vellum-white);
    background-image:
        radial-gradient(
            ellipse at var(--wash-x, 50%) var(--wash-y, 50%),
            var(--wash-hue, rgba(74, 124, 89, 0.04)),
            transparent 70%
        );
    position: relative;
    clip-path: polygon(
        0% var(--tear-1, 2%),
        12.5% var(--tear-2, 5%),
        25% var(--tear-3, 1%),
        37.5% var(--tear-4, 4%),
        50% var(--tear-5, 3%),
        62.5% var(--tear-6, 6%),
        75% var(--tear-7, 2%),
        87.5% var(--tear-8, 4%),
        100% var(--tear-1, 2%),
        100% 100%,
        0% 100%
    );
    box-shadow:
        4px 4px 8px rgba(26, 58, 42, 0.1),
        2px 2px 4px rgba(26, 58, 42, 0.05);
    transition: box-shadow 300ms ease;
    overflow: hidden;
}

.entry-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        circle at var(--mx, 50%) var(--my, 50%),
        rgba(74, 124, 89, 0.08) 0%,
        transparent 70%
    );
    opacity: 0;
    transition: opacity 500ms ease;
    pointer-events: none;
    z-index: 1;
}

.entry-card.hovered::after {
    opacity: 1;
    transition: opacity 500ms ease;
}

.entry-card.hover-leaving::after {
    opacity: 0;
    transition: opacity 400ms ease;
}

/* --- Paper curl pseudo-element --- */
.entry-card::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 24px;
    height: 24px;
    background: conic-gradient(
        from 225deg at 100% 100%,
        var(--aged-folio) 0deg,
        rgba(26, 58, 42, 0.08) 90deg,
        transparent 180deg
    );
    z-index: 2;
    pointer-events: none;
}

/* --- Entry Title --- */
.entry-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    color: var(--deep-canopy);
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 12px;
    position: relative;
    z-index: 2;
    min-height: 1.4em;
}

/* --- Entry Body --- */
.entry-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.05rem);
    line-height: 1.72;
    color: var(--deep-bark);
    margin-bottom: 12px;
    position: relative;
    z-index: 2;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.entry-card.revealed .entry-body {
    opacity: 1;
    transform: translateY(0);
}

.entry-italic {
    font-style: italic;
    color: var(--moss-ink);
}

/* --- Tech Labels (in SVGs and cards) --- */
.tech-label {
    font-family: var(--font-tech);
    font-weight: 400;
    font-size: clamp(0.65rem, 0.8vw, 0.75rem);
    fill: var(--deep-pine);
    letter-spacing: 0.06em;
    text-transform: lowercase;
}

/* ============================================
   SPECIMEN LABELS
   ============================================ */
.specimen-label {
    position: relative;
    display: inline-block;
    width: 160px;
    height: 28px;
    border: 1px solid var(--deep-pine);
    background-color: #f0e8d6;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    padding-left: 18px;
    z-index: 3;
    margin-top: -4px;
}

.label-pin {
    position: absolute;
    top: -4px;
    left: 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--burnt-umber-wash);
    box-shadow: inset -1px -1px 0 rgba(0, 0, 0, 0.2);
}

.label-pin::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
}

.label-text {
    font-family: var(--font-tech);
    font-weight: 400;
    font-size: 0.6rem;
    color: var(--deep-pine);
    letter-spacing: 0.06em;
    text-transform: lowercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   MARGIN ANNOTATIONS
   ============================================ */
.margin-annotation {
    break-inside: avoid;
    display: inline-block;
    width: 100%;
    margin-bottom: 16px;
    padding: 8px 12px;
    transform: rotate(var(--rotate, 0deg));
    position: relative;
    z-index: 2;
}

.annotation-text {
    font-family: var(--font-annotation);
    font-weight: 400;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    color: var(--moss-ink);
    letter-spacing: 0.01em;
    font-style: italic;
    line-height: 1.4;
}

/* ============================================
   BOTANICAL CIRCUIT SVGs
   ============================================ */
.botanical-circuit {
    display: block;
    width: 100%;
    max-width: 220px;
    margin: 16px auto 8px;
    position: relative;
    z-index: 2;
}

.botanical-circuit text {
    font-family: var(--font-tech);
    letter-spacing: 0.06em;
}

/* ============================================
   CIRCUIT TRACE PATHS (scroll-drawn)
   ============================================ */
.circuit-trace-path {
    stroke: var(--spring-moss);
    stroke-width: 0.8;
    stroke-opacity: 0.25;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    will-change: stroke-dashoffset;
}

.circuit-trace-dot {
    fill: var(--spring-moss);
    fill-opacity: 0.3;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    :root {
        --spine-width: 36px;
    }

    .page-surface {
        padding: 40px 20px 60px;
    }

    .spine-label {
        font-size: 0.6rem;
        gap: 32px;
    }

    .folio-spine {
        gap: 32px;
    }

    .specimen-label {
        width: 140px;
    }

    .botanical-circuit {
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    :root {
        --spine-width: 0px;
    }

    .folio-spine {
        display: none;
    }

    .page-surface {
        margin-left: 0;
        padding: 30px 16px 40px;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .journal-cover {
        transition: opacity 200ms ease;
    }

    .journal-cover.opening {
        transform: none;
        opacity: 0;
    }

    .entry-body {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .typewriter-cursor {
        animation: none !important;
        display: none !important;
    }

    .folio-spine {
        transition: none;
    }

    .entry-card::after {
        transition: none;
    }

    #sporeCanvas {
        display: none;
    }
}

/* ============================================
   SELECTION STYLES
   ============================================ */
::selection {
    background-color: rgba(74, 124, 89, 0.2);
    color: var(--deep-bark);
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--aged-folio);
}

::-webkit-scrollbar-thumb {
    background: var(--lichen-silver);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--spring-moss);
}
