/* ================================================
   plotgrapher.com — Burned Manuscript Laboratory
   ================================================ */

/* --- CSS Custom Properties --- */
:root {
    --abyss-black: #0a0a08;
    --desk-walnut: #1a1410;
    --parchment-bone: #d4c9a8;
    --typewriter-ink: #1c1812;
    --editor-red: #a63220;
    --thread-crimson: #cc3d2a;
    --lamp-amber: #c9873a;
    --smoke-gray: #6b6158;
    --ash-pale: #8a8070;
    --shadow-blue: #3a3d42;
    --dark-accent: #2a2820;
    --deep-brown: #3a2810;
    --deep-ink: #3a1c0e;
}

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

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

body {
    background-color: var(--abyss-black);
    color: var(--parchment-bone);
    font-family: 'Special Elite', monospace;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.02em;
    overflow-x: hidden;
}

/* --- Noise Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    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.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* --- Chapter Navigation (Torn Paper Tabs) --- */
#chapter-nav {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chapter-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 48px;
    background: var(--parchment-bone);
    color: var(--typewriter-ink);
    font-family: 'Special Elite', monospace;
    font-size: 0.85rem;
    text-decoration: none;
    clip-path: polygon(15% 0%, 100% 0%, 100% 100%, 15% 100%, 0% 85%, 5% 70%, 0% 55%, 3% 40%, 0% 25%, 5% 10%);
    transition: background 0.3s, width 0.3s;
}

.chapter-tab:hover,
.chapter-tab.active {
    background: var(--editor-red);
    color: var(--parchment-bone);
    width: 50px;
}

/* --- Generic Chapter Styles --- */
.chapter {
    position: relative;
    overflow: hidden;
}

/* --- Section Rule (typewriter underscores) --- */
.section-rule {
    width: 100%;
    height: 6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.section-rule::before {
    content: '________________________________________';
    font-family: 'Special Elite', monospace;
    color: var(--smoke-gray);
    opacity: 0.3;
    letter-spacing: 0.3em;
    font-size: 0.8rem;
}

/* --- Typewriter Key Stamps --- */
.typewriter-key-stamp {
    position: absolute;
    font-family: 'Special Elite', monospace;
    font-size: clamp(150px, 20vw, 300px);
    color: var(--parchment-bone);
    opacity: 0.04;
    pointer-events: none;
    z-index: 0;
    user-select: none;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
}

/* --- Coffee Ring Stains --- */
.coffee-ring {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.12;
    filter: blur(8px);
}

.coffee-ring-1 {
    width: 220px;
    height: 220px;
    bottom: 15%;
    left: 8%;
    background: radial-gradient(ellipse at center, transparent 55%, var(--deep-brown) 60%, transparent 70%);
}

.coffee-ring-2 {
    width: 180px;
    height: 180px;
    top: 20%;
    right: 12%;
    background: radial-gradient(ellipse at center, transparent 50%, var(--deep-brown) 58%, transparent 68%);
}

.coffee-ring-3 {
    width: 260px;
    height: 260px;
    bottom: 8%;
    right: 5%;
    background: radial-gradient(ellipse at center, transparent 55%, var(--deep-brown) 62%, transparent 72%);
}

.coffee-ring-4 {
    width: 200px;
    height: 200px;
    top: 10%;
    left: 5%;
    background: radial-gradient(ellipse at center, transparent 52%, var(--deep-brown) 58%, transparent 68%);
}

/* --- Cursor Blink --- */
.cursor {
    color: var(--editor-red);
    animation: cursorBlink 0.8s step-end infinite;
    font-weight: 400;
}

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

/* ============================
   CHAPTER I — The Desk
   ============================ */
.chapter-desk {
    min-height: 100vh;
    background-color: var(--desk-walnut);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.desk-lamp-glow {
    position: absolute;
    top: 0;
    right: 0;
    width: 60%;
    height: 60%;
    background: radial-gradient(ellipse at top right, rgba(201,135,58,0.08) 0%, transparent 60%);
    pointer-events: none;
    z-index: 1;
}

.desk-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 2rem;
}

.title-main {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2.8rem, 6vw, 5.2rem);
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--parchment-bone);
    text-shadow: 1px 1px 0 var(--deep-ink), -1px -1px 0 rgba(0,0,0,0.3);
    line-height: 1.1;
    margin-bottom: 1.5rem;
    min-height: 1.2em;
}

.title-text {
    display: inline;
}

.subtitle {
    font-family: 'Special Elite', monospace;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    color: var(--ash-pale);
    letter-spacing: 0.05em;
    line-height: 1.75;
    min-height: 1.75em;
}

.subtitle-text {
    display: inline;
}

.subtitle-cursor {
    display: none;
}

.subtitle-cursor.active {
    display: inline;
}

/* Keystrike bounce animation */
@keyframes keystrike {
    0% { transform: translateY(-2px); opacity: 0; }
    30% { transform: translateY(1px); opacity: 1; }
    100% { transform: translateY(0); opacity: 1; }
}

.char-animate {
    display: inline-block;
    animation: keystrike 0.12s ease-out forwards;
}

/* ============================
   CHAPTER II — The Pinboard
   ============================ */
.chapter-pinboard {
    min-height: 200vh;
    background-color: var(--abyss-black);
    position: relative;
    padding: 8rem 5% 6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4rem;
}

.red-threads-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.thread-line {
    stroke: var(--thread-crimson);
    stroke-width: 1.5;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 0.5s ease;
}

.thread-line.drawn {
    stroke-dashoffset: 0;
}

.thread-node {
    fill: var(--thread-crimson);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.thread-node.visible {
    opacity: 1;
    filter: drop-shadow(0 0 6px var(--lamp-amber));
    animation: nodePulse 2s ease-in-out infinite;
}

@keyframes nodePulse {
    0%, 100% { filter: drop-shadow(0 0 4px var(--lamp-amber)); }
    50% { filter: drop-shadow(0 0 12px var(--lamp-amber)); }
}

/* Pinboard Cards */
.pinboard-card {
    position: relative;
    z-index: 2;
    max-width: 580px;
    width: 90%;
    padding: 2.5rem 2rem 2rem;
    transform: rotate(var(--rot, 0deg));
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.pinboard-card.visible {
    opacity: 1;
    transform: rotate(var(--rot, 0deg)) translateY(0);
}

/* Z-pattern positioning */
.pinboard-card:nth-child(odd) {
    align-self: flex-start;
    margin-left: 5%;
}

.pinboard-card:nth-child(even) {
    align-self: flex-end;
    margin-right: 5%;
}

/* Card paper textures */
.card-graph {
    background-color: rgba(26,20,16,0.9);
    background-image:
        linear-gradient(var(--dark-accent) 1px, transparent 1px),
        linear-gradient(90deg, var(--dark-accent) 1px, transparent 1px);
    background-size: 1.75em 1.75em;
    border: 1px solid rgba(107,97,88,0.2);
}

.card-lined {
    background-color: rgba(26,20,16,0.9);
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent calc(1.75em - 1px),
        var(--dark-accent) calc(1.75em - 1px),
        var(--dark-accent) 1.75em
    );
    border: 1px solid rgba(107,97,88,0.2);
}

.card-parchment {
    background-color: rgba(212,201,168,0.08);
    border: 1px solid rgba(107,97,88,0.15);
}

.card-envelope {
    background-color: rgba(26,20,16,0.85);
    border: 1px solid rgba(107,97,88,0.25);
    background-image: linear-gradient(135deg, transparent 48%, rgba(107,97,88,0.1) 49%, rgba(107,97,88,0.1) 51%, transparent 52%);
}

/* Burn marks on cards */
.pinboard-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 40%;
    height: 40%;
    background: radial-gradient(ellipse at top right, rgba(10,6,2,0.7) 0%, transparent 70%);
    mix-blend-mode: multiply;
    pointer-events: none;
    z-index: 3;
}

/* Torn paper edges */
.pinboard-card {
    clip-path: polygon(
        0% 2%, 5% 0%, 12% 1%, 20% 0%, 28% 2%, 35% 0%, 43% 1%, 50% 0%, 58% 2%, 65% 0%, 73% 1%, 80% 0%, 88% 2%, 95% 0%, 100% 1%,
        100% 98%, 95% 100%, 88% 99%, 80% 100%, 73% 98%, 65% 100%, 58% 99%, 50% 100%, 43% 98%, 35% 100%, 28% 99%, 20% 100%, 12% 98%, 5% 100%, 0% 99%
    );
}

/* Pin */
.pin {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, var(--editor-red), #5a1510);
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
    z-index: 5;
}

.card-heading {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--parchment-bone);
    text-shadow: 1px 1px 0 var(--deep-ink), -1px -1px 0 rgba(0,0,0,0.3);
    margin-bottom: 1rem;
}

.card-body {
    font-family: 'Special Elite', monospace;
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    color: var(--parchment-bone);
    line-height: 1.75;
    margin-bottom: 1rem;
}

.card-annotation {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.8rem, 1.4vw, 1.05rem);
    font-weight: 700;
    color: var(--editor-red);
    display: block;
    text-align: right;
    font-style: italic;
}

/* ============================
   CHAPTER III — The Roots
   ============================ */
.chapter-roots {
    min-height: 150vh;
    background-color: var(--abyss-black);
    position: relative;
    padding: 6rem 5%;
}

.root-svg {
    position: absolute;
    top: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 1000px;
    height: 80%;
    z-index: 0;
    pointer-events: none;
}

.root-path {
    fill: none;
    stroke: var(--smoke-gray);
    stroke-width: 2;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 0.3s ease;
    opacity: 0.6;
}

.root-main {
    stroke-width: 3;
    opacity: 0.8;
}

.root-tendril {
    stroke-width: 1;
    opacity: 0.4;
}

.leaf-watermark {
    pointer-events: none;
}

.roots-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 12rem;
    padding: 8rem 0;
    max-width: 900px;
    margin: 0 auto;
}

.root-text-block {
    max-width: 480px;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.root-text-block.visible {
    opacity: 1;
    transform: translateY(0);
}

.root-text-1 {
    align-self: flex-start;
}

.root-text-2 {
    align-self: flex-end;
}

.root-text-3 {
    align-self: center;
}

.roots-heading {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--parchment-bone);
    text-shadow: 1px 1px 0 var(--deep-ink), -1px -1px 0 rgba(0,0,0,0.3);
    margin-bottom: 1rem;
}

.root-text-block p {
    font-family: 'Special Elite', monospace;
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    color: var(--parchment-bone);
    line-height: 1.75;
}

/* Nature Specimens */
.specimen {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}

.specimen-fern {
    width: 80px;
    right: 8%;
    top: 15%;
}

.specimen-seedpod {
    width: 50px;
    left: 6%;
    bottom: 20%;
}

/* ============================
   CHAPTER IV — The Last Page
   ============================ */
.chapter-lastpage {
    min-height: 100vh;
    background: linear-gradient(to bottom, var(--abyss-black) 0%, #000000 40%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8rem 2rem;
    position: relative;
}

.typewriter-column {
    max-width: 52ch;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

.lastpage-paragraph {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.lastpage-paragraph.visible {
    opacity: 1;
    transform: translateY(0);
}

.typewriter-reveal {
    font-family: 'Special Elite', monospace;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    color: var(--parchment-bone);
    line-height: 1.75;
    letter-spacing: 0.02em;
}

.lastpage-final {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.lastpage-final.visible {
    opacity: 1;
    transform: translateY(0);
}

.final-typed {
    font-family: 'Special Elite', monospace;
    font-size: clamp(1.2rem, 2.2vw, 1.5rem);
    color: var(--parchment-bone);
    letter-spacing: 0.05em;
}

.final-cursor {
    color: var(--editor-red);
    animation: cursorBlink 0.8s step-end infinite;
}

.cta-annotation {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    text-align: right;
    padding-top: 2rem;
}

.cta-annotation.visible {
    opacity: 1;
    transform: translateY(0);
}

.annotation-cta {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    font-weight: 700;
    color: var(--editor-red);
    cursor: pointer;
    position: relative;
    display: inline-block;
    transition: color 0.3s ease;
}

.annotation-cta:hover {
    color: var(--thread-crimson);
    text-shadow: 0 0 20px rgba(204,61,42,0.4);
}

.annotation-cta::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--thread-crimson);
    transition: width 0.3s ease;
}

.annotation-cta:hover::after {
    width: 100%;
}

/* --- Card animation base state --- */
.card-animate {
    opacity: 0;
    transform: translateY(30px) rotate(var(--rot, 0deg));
}

.card-animate.visible {
    opacity: 1;
    transform: translateY(0) rotate(var(--rot, 0deg));
    transition: opacity 0.7s ease, transform 0.7s ease;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #chapter-nav {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        transform: none;
        flex-direction: row;
        justify-content: center;
        gap: 2px;
        background: rgba(10,10,8,0.9);
        padding: 4px 0;
    }

    .chapter-tab {
        width: 40px;
        height: 36px;
        clip-path: polygon(0% 15%, 15% 0%, 85% 0%, 100% 15%, 100% 100%, 0% 100%);
    }

    .pinboard-card:nth-child(odd),
    .pinboard-card:nth-child(even) {
        align-self: center;
        margin-left: 0;
        margin-right: 0;
    }

    .chapter-pinboard {
        padding: 4rem 3% 4rem;
        gap: 3rem;
    }

    .roots-content {
        gap: 6rem;
    }

    .root-text-1,
    .root-text-2,
    .root-text-3 {
        align-self: center;
        max-width: 100%;
    }

    .specimen-fern {
        width: 50px;
    }

    .specimen-seedpod {
        width: 35px;
    }
}

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

    .card-animate {
        opacity: 1;
        transform: none;
    }

    .card-animate.visible {
        transition: none;
    }

    .thread-line {
        stroke-dashoffset: 0;
        transition: none;
    }

    .thread-node {
        opacity: 1;
        animation: none;
    }

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

    .char-animate {
        animation: none;
        opacity: 1;
    }

    .pinboard-card {
        opacity: 1;
    }

    .lastpage-paragraph,
    .lastpage-final,
    .cta-annotation,
    .root-text-block {
        opacity: 1;
        transform: none;
    }

    .thread-node.visible {
        animation: none;
    }
}
