/* undo.systems - Main Stylesheet */

/* ===== CSS Variables & Root Styles ===== */
:root {
    /* Color Palette */
    --aged-vellum: #1C1A17;
    --dark-walnut: #2A2622;
    --inkwash: #3D3830;
    --parchment-light: #E8E0D4;
    --faded-script: #B5AA9A;
    --aged-graphite: #6B6560;
    --oxidized-ink: #8A7E6E;
    --candlelight: #C9B88A;

    /* Typography */
    --font-primary: 'Commissioner', sans-serif;
    --font-mono: 'Courier Prime', monospace;

    /* Spacing */
    --margin-width: 15vw;
}

/* ===== Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    background-color: var(--aged-vellum);
}

body {
    font-family: var(--font-primary);
    background-color: var(--aged-vellum);
    color: var(--parchment-light);
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
}

/* Aged paper grain texture background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    background-color: var(--aged-vellum);
    background-image:
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="4" result="noise" /><feColorMatrix in="noise" type="saturate" values="0" /></filter><rect width="100" height="100" fill="%231C1A17" filter="url(%23noise)" opacity="0.03" /></svg>');
    opacity: 0.03;
}

/* ===== Overture Section ===== */
.overture {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background-color: var(--aged-vellum);
}

.overture-content {
    text-align: center;
    position: relative;
}

.overture .typewriter-text {
    font-size: clamp(2.8rem, 6vw, 5.5rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--parchment-light);
    line-height: 1.2;
    display: inline-block;
}

#overture-text {
    opacity: 0;
    animation: none;
}

.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background-color: var(--candlelight);
    margin-left: 0.1em;
    animation: blink 1.06s infinite;
    opacity: 0;
}

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

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    animation: bounce 2s infinite;
    opacity: 0;
}

.chevron-icon {
    width: 24px;
    height: 24px;
    animation: bounceChevron 2s infinite;
}

@keyframes bounce {
    0%, 100% { opacity: 0.6; transform: translateX(-50%) translateY(0); }
    50% { opacity: 1; transform: translateX(-50%) translateY(8px); }
}

@keyframes bounceChevron {
    0% { transform: translateY(-2px); }
    50% { transform: translateY(2px); }
}

/* ===== Spine SVG Styling ===== */
#spine-line {
    position: fixed;
    top: 0;
    left: calc(var(--margin-width) + 50%);
    width: 2px;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    transform: translateX(-50%);
}

#spine-path {
    stroke-dasharray: 5000;
    stroke-dashoffset: 5000;
    transition: stroke-dashoffset 0.1s linear;
}

.spine-node {
    cx: 1;
    r: 4;
    fill: none;
    stroke: var(--inkwash);
    stroke-width: 1;
}

.spine-node.active {
    fill: var(--oxidized-ink);
    stroke: var(--oxidized-ink);
}

/* ===== Page Container & Layout ===== */
.page-container {
    display: grid;
    grid-template-columns: var(--margin-width) 1fr;
    gap: 2rem;
    position: relative;
    background-color: var(--aged-vellum);
    padding: 0;
    margin: 0;
}

/* ===== Margin Column ===== */
.margin-column {
    grid-column: 1;
    padding: 3rem 1.5rem 2rem 1rem;
    position: relative;
    border-right: 1px solid var(--inkwash);
    min-height: 100vh;
    font-size: 0.8rem;
    line-height: 1.5;
}

.stratum-nav {
    display: flex;
    flex-direction: column;
    gap: 3rem;
    margin-bottom: 4rem;
    position: sticky;
    top: 2rem;
}

.nav-marker {
    font-family: var(--font-primary);
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--aged-graphite);
    text-decoration: none;
    opacity: 0.3;
    transition: opacity 0.3s ease;
    cursor: pointer;
    letter-spacing: 0.05em;
}

.nav-marker:hover,
.nav-marker.active {
    opacity: 1;
}

.margin-notes {
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.annotation {
    font-size: 0.75rem;
    color: var(--aged-graphite);
    opacity: 0;
    transition: opacity 0.4s ease;
    padding-left: 1.5rem;
    position: relative;
}

.annotation.visible {
    opacity: 0.7;
}

.annotation-mark {
    position: absolute;
    left: 0;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--aged-graphite);
}

.annotation time {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--aged-graphite);
    margin-bottom: 0.3rem;
}

.annotation p {
    font-style: italic;
    font-weight: 300;
    color: var(--aged-graphite);
    margin: 0;
}

/* ===== Content Area ===== */
.content-area {
    grid-column: 2;
    padding-right: 3rem;
}

/* ===== Stratum Sections ===== */
.stratum {
    min-height: 80vh;
    padding: 4rem 3rem;
    background-color: var(--dark-walnut);
    margin: 2rem 0;
    border: 1px solid var(--inkwash);
    opacity: 0;
    transform: translateY(20px);
    animation: none;
    transition: opacity 1.2s cubic-bezier(0.25, 0.1, 0.25, 1.0), transform 1.2s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.stratum.visible {
    opacity: 1;
    transform: translateY(0);
}

.stratum-content {
    max-width: 90%;
    position: relative;
}

.stratum h2 {
    font-size: clamp(1.4rem, 2.8vw, 2.2rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--parchment-light);
    margin: 2rem 0 1.5rem 0;
    line-height: 1.3;
}

.stratum p {
    font-size: clamp(1rem, 1.6vw, 1.15rem);
    color: var(--parchment-light);
    margin: 0 0 1.8em 0;
    text-indent: 2.5em;
    line-height: 1.75;
    letter-spacing: 0.01em;
}

.stratum p:first-of-type {
    text-indent: 2.5em;
}

/* ===== Stratum Typewriter Sequences ===== */
.stratum-typewriter {
    margin-bottom: 2rem;
    position: relative;
    min-height: 1.5rem;
}

.stratum .typewriter-text {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--aged-graphite);
    font-weight: 400;
    letter-spacing: 0;
    margin: 0;
}

.stratum .typewriter-cursor {
    width: 1px;
    height: 0.85rem;
    background-color: var(--candlelight);
}

/* ===== Interstitial Sections ===== */
.interstitial {
    min-height: 40vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 3rem;
    margin: 2rem 0;
    background-color: var(--aged-vellum);
    border-bottom: 1px solid var(--inkwash);
}

.epigraph {
    font-size: clamp(1.2rem, 2.2vw, 1.8rem);
    color: var(--faded-script);
    font-style: italic;
    text-align: center;
    max-width: 80%;
    line-height: 1.8;
    letter-spacing: 0.01em;
    opacity: 0;
    animation: fadeInEpigraph 0.8s ease-out 0.4s forwards;
}

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

/* ===== Terminal Section ===== */
.terminal-section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 3rem;
    background-color: var(--aged-vellum);
    margin-top: 2rem;
    border-top: 1px solid var(--inkwash);
    position: relative;
}

.terminal-content {
    text-align: center;
    max-width: 100%;
}

.terminal-section .typewriter-text {
    font-size: clamp(2.8rem, 6vw, 5.5rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--parchment-light);
    opacity: 0;
    animation: none;
}

.terminal-section .typewriter-cursor {
    margin-left: 0.1em;
    display: inline-block;
}

.terminal-epigraph {
    font-size: 1.2rem;
    color: var(--aged-graphite);
    font-style: italic;
    margin-top: 2rem;
    opacity: 0;
    animation: fadeInEpigraph 0.8s ease-out 1s forwards;
}

/* ===== Decorative SVG Curves ===== */
.flow-curve {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.4;
}

.flow-curve path {
    stroke: var(--inkwash);
    stroke-width: 0.5px;
    fill: none;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

/* ===== Scrolling Spine Animation ===== */
.spine-node-circle {
    position: absolute;
    width: 8px;
    height: 8px;
    border: 1px solid var(--oxidized-ink);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s ease, fill 0.3s ease;
    left: calc(var(--margin-width) + 50% - 4px);
}

.spine-node-circle.visible {
    opacity: 1;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 1024px) {
    :root {
        --margin-width: 18vw;
    }

    .page-container {
        grid-template-columns: var(--margin-width) 1fr;
        gap: 1rem;
    }

    .content-area {
        padding-right: 2rem;
    }

    .stratum {
        padding: 3rem 2rem;
    }

    .stratum-content {
        max-width: 95%;
    }
}

@media (max-width: 768px) {
    :root {
        --margin-width: 0;
    }

    .page-container {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .margin-column {
        display: none;
    }

    .margin-column.mobile-visible {
        display: block;
        grid-column: 1;
        padding: 2rem 1.5rem;
        border-right: none;
        border-bottom: 1px solid var(--inkwash);
        margin-bottom: 2rem;
    }

    #spine-line {
        left: 1.5rem;
        width: 1px;
    }

    .stratum {
        min-height: auto;
        padding: 2rem 1.5rem;
        margin: 1.5rem 0;
    }

    .stratum h2 {
        font-size: clamp(1.2rem, 4vw, 1.8rem);
        margin: 1.5rem 0 1rem 0;
    }

    .stratum p {
        font-size: 1rem;
        text-indent: 1.5em;
    }

    .interstitial {
        min-height: 30vh;
        padding: 2rem 1.5rem;
    }

    .epigraph {
        font-size: clamp(1rem, 3vw, 1.4rem);
        max-width: 95%;
    }

    .content-area {
        padding-right: 1.5rem;
    }

    .overture .typewriter-text {
        font-size: clamp(2rem, 8vw, 4rem);
    }

    .scroll-indicator {
        display: none;
    }
}

@media (max-width: 480px) {
    .stratum {
        padding: 1.5rem 1rem;
    }

    .stratum p {
        text-indent: 1.2em;
        font-size: 0.95rem;
    }

    .stratum h2 {
        font-size: 1.3rem;
        margin: 1.2rem 0 0.8rem 0;
    }

    .content-area {
        padding-right: 1rem;
    }
}

/* ===== Animation States ===== */
.typewriter-text span {
    opacity: 0;
    display: inline;
}

.typewriter-text span.visible {
    opacity: 1;
}

/* ===== Print Styles ===== */
@media print {
    body::before {
        display: none;
    }

    .scroll-indicator,
    .spine-line,
    .stratum-nav {
        display: none;
    }

    .stratum,
    .interstitial {
        page-break-inside: avoid;
        break-inside: avoid;
    }
}
