/* ============================================
   alth.ing - Styles
   Hand-drawn futurism through an academic lens
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Color Palette (Sunset-Warm) */
    --parchment-dusk: #F5EDE0;
    --twilight-linen: #EDE2D0;
    --ink-sepia: #2C1E10;
    --burnt-umber-mist: #6B4C36;
    --terracotta-ember: #C9593A;
    --saffron-glow: #E8A435;
    --dusted-mauve: #9E7B8F;
    --charcoal-dusk: #1F1A15;
    --wheat-glow: #E8C4A0;

    /* Typography */
    --font-body: 'Cormorant Garamond', 'Georgia', serif;
    --font-display: 'Caveat', cursive;
    --font-accent: 'Space Grotesk', 'Arial', sans-serif;

    /* Spacing */
    --page-padding: clamp(3rem, 6vh, 5rem);

    /* Transition */
    --slide-easing: cubic-bezier(0.76, 0, 0.24, 1);
    --slide-duration: 800ms;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--parchment-dusk);
    color: var(--ink-sepia);
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.8;
    letter-spacing: 0.01em;
    -webkit-font-smoothing: antialiased;
}

/* --- Grain Overlay (fixed, above everything) --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.07;
    mix-blend-mode: multiply;
}

#grain-overlay::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 300px 300px;
}

/* Dark page grain adjustment */
.page-colophon #grain-overlay {
    mix-blend-mode: overlay;
    opacity: 0.1;
}

/* --- SVG Defs (hidden) --- */
#svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- SVG annotation text style --- */
.svg-annotation {
    font-family: 'Caveat', cursive;
}

/* --- Navigation Timeline --- */
#nav-timeline {
    position: fixed;
    left: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    opacity: 0;
    transition: opacity 0.8s ease 1s;
}

#nav-timeline.visible {
    opacity: 1;
}

#nav-line-svg {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 100%;
    z-index: -1;
}

.waypoint {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    padding: 0.8rem 0;
    position: relative;
}

.waypoint-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid var(--terracotta-ember);
    background: transparent;
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

.waypoint.active .waypoint-dot {
    background: var(--terracotta-ember);
}

.waypoint.visited .waypoint-dot {
    border-color: var(--burnt-umber-mist);
    background: transparent;
}

.waypoint-label {
    font-family: var(--font-accent);
    font-size: 0.7rem;
    font-weight: 300;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--burnt-umber-mist);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.waypoint:hover .waypoint-label {
    opacity: 1;
    transform: translateX(0);
}

/* --- Page Container --- */
#page-container {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* --- Page Base --- */
.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--parchment-dusk);
    will-change: transform, opacity;
    transform: translateX(100%);
    opacity: 0;
    transition: transform var(--slide-duration) var(--slide-easing),
                opacity var(--slide-duration) var(--slide-easing);
}

.page.active {
    transform: translateX(0);
    opacity: 1;
}

.page.exiting-left {
    transform: translateX(-100%);
    opacity: 0.3;
}

.page.entering-right {
    transform: translateX(100%);
    opacity: 0;
}

/* --- Page Inner Layout (folio + marginalia) --- */
.page-inner {
    display: flex;
    width: 100%;
    height: 100%;
    padding: var(--page-padding);
    padding-left: 4rem;
}

/* --- Folio (left 62%) --- */
.folio {
    flex: 0 0 62%;
    max-width: 62%;
    padding-right: clamp(2rem, 3vw, 4rem);
    position: relative;
    overflow-y: auto;
    scrollbar-width: none;
}

.folio::-webkit-scrollbar {
    display: none;
}

/* Ruled lines background */
.ruled-lines-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent calc(2rem - 1px),
        rgba(232, 196, 160, 0.08) calc(2rem - 1px),
        rgba(232, 196, 160, 0.08) 2rem
    );
    z-index: 0;
}

/* --- Marginalia (right 38%) --- */
.marginalia {
    flex: 0 0 38%;
    max-width: 38%;
    padding-left: clamp(1.5rem, 2vw, 3rem);
    position: relative;
    background-color: var(--twilight-linen);
    box-shadow: inset 2px 0 4px rgba(44, 30, 16, 0.08);
    padding-top: var(--page-padding);
    padding-right: 1.5rem;
    overflow-y: auto;
    scrollbar-width: none;
}

.marginalia::-webkit-scrollbar {
    display: none;
}

/* --- Section Headings --- */
.section-heading {
    font-family: var(--font-display);
    font-size: clamp(2rem, 4vw, 3.8rem);
    font-weight: 700;
    color: var(--ink-sepia);
    margin-bottom: 2rem;
    position: relative;
    z-index: 1;
}

/* ============================================
   PAGE 1: THE INSCRIPTION
   ============================================ */
.page-inscription {
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-inscription .page-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

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

.inscription-title {
    font-family: var(--font-display);
    font-size: clamp(4rem, 8vw, 7rem);
    font-weight: 700;
    color: var(--ink-sepia);
    line-height: 1.1;
    margin-bottom: 0.5rem;
}

.inscription-underline {
    width: clamp(200px, 30vw, 400px);
    height: auto;
    display: block;
    margin: 0 auto 1.5rem;
}

.inscription-underline .hand-drawn-line {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
}

.page.active .inscription-underline .hand-drawn-line {
    animation: drawLine 1.5s cubic-bezier(0.4, 0, 0.2, 1) 0.3s forwards;
}

.inscription-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(1.1rem, 1.5vw, 1.4rem);
    color: var(--burnt-umber-mist);
    font-weight: 400;
    letter-spacing: 0.02em;
}

.scroll-hint {
    margin-top: 3rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease 2s forwards;
}

.scroll-arrow {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: drawLine 1s ease 2.5s forwards;
}

/* ============================================
   PAGE 2: THE HYPOTHESIS
   ============================================ */
.cellular-diagram {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 2rem;
    position: relative;
    z-index: 1;
}

.cell-svg {
    width: 100%;
    height: auto;
}

.cell-stroke {
    stroke-dashoffset: 1400;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.page.active .cell-stroke {
    stroke-dashoffset: 0;
}

.cell-fade {
    transition: opacity 0.8s ease;
}

.page.active .cell-fade {
    opacity: 0.6;
}

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

.folio-text p {
    margin-bottom: 1.2rem;
    font-weight: 400;
    color: var(--ink-sepia);
}

/* Margin notes */
.margin-note {
    margin-bottom: 1.5rem;
    padding: 0.8rem;
    position: relative;
}

.manicule,
.margin-icon {
    display: block;
    margin-bottom: 0.4rem;
}

.pull-quote {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    color: var(--ink-sepia);
    border-left: 2px solid var(--dusted-mauve);
    padding-left: 0.8rem;
    line-height: 1.5;
}

.margin-text {
    font-family: var(--font-display);
    font-size: clamp(0.9rem, 1.2vw, 1.1rem);
    color: var(--burnt-umber-mist);
    line-height: 1.5;
}

.margin-annotation {
    font-family: var(--font-display);
    font-size: clamp(0.95rem, 1.3vw, 1.15rem);
    color: var(--burnt-umber-mist);
    line-height: 1.5;
}

/* ============================================
   PAGE 3: THE EVIDENCE
   ============================================ */
.timeline-container {
    position: relative;
    margin: 2rem 0;
    z-index: 1;
}

.timeline-svg {
    width: 100%;
    height: auto;
}

.timeline-line {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 2s cubic-bezier(0.4, 0, 0.2, 1);
}

.page.active .timeline-line {
    stroke-dashoffset: 0;
}

.timeline-waypoint {
    cursor: pointer;
}

.timeline-waypoint:hover {
    opacity: 0.8;
}

.timeline-date {
    font-family: 'Caveat', cursive;
}

/* Milestone cards */
.milestone-card {
    position: absolute;
    bottom: 100%;
    background-color: var(--twilight-linen);
    padding: 1rem 1.2rem;
    width: 200px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
    z-index: 10;
}

.milestone-card.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.milestone-card[data-milestone="0"] { left: 5%; }
.milestone-card[data-milestone="1"] { left: 25%; }
.milestone-card[data-milestone="2"] { left: 48%; }
.milestone-card[data-milestone="3"] { left: 68%; }

.milestone-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink-sepia);
    margin-bottom: 0.3rem;
}

.milestone-desc {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--burnt-umber-mist);
    line-height: 1.5;
}

/* Callout box */
.callout-box {
    position: relative;
    margin: 3rem 0 2rem;
    padding: 2rem;
    z-index: 1;
}

.callout-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.callout-text {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(1rem, 1.3vw, 1.2rem);
    color: var(--ink-sepia);
    line-height: 1.8;
    position: relative;
    z-index: 1;
}

/* Circuit-botanical in marginalia */
.circuit-botanical {
    margin-bottom: 2rem;
}

.circuit-botanical-svg {
    width: 100%;
    max-width: 200px;
    height: auto;
}

/* ============================================
   PAGE 4: THE DIAGRAM
   ============================================ */
.anatomical-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.anatomical-svg {
    width: 100%;
    height: auto;
}

.anat-layer {
    transition: opacity 0.6s ease;
}

.marginalia-dense {
    padding-top: clamp(2rem, 4vh, 4rem);
}

.leader-lines {
    position: absolute;
    left: -2rem;
    top: 30%;
}

/* ============================================
   PAGE 5: THE MARGINALIA (role reversal)
   ============================================ */
.page-inner-reversed {
    flex-direction: row-reverse;
}

.folio-narrow {
    flex: 0 0 30%;
    max-width: 30%;
    padding-left: clamp(1.5rem, 2vw, 3rem);
    padding-right: clamp(1rem, 1.5vw, 2rem);
    display: flex;
    align-items: center;
}

.marginalia-expanded {
    flex: 0 0 70%;
    max-width: 70%;
    padding-top: var(--page-padding);
    padding-left: 2rem;
    padding-right: 2rem;
}

.margin-heading {
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    margin-bottom: 2rem;
}

.long-quote {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.3vw, 1.2rem);
    color: var(--ink-sepia);
    line-height: 2;
    position: relative;
    z-index: 1;
}

.long-quote p {
    margin-bottom: 1rem;
    font-style: italic;
}

.long-quote cite {
    display: block;
    font-family: var(--font-display);
    font-style: normal;
    font-size: 1rem;
    color: var(--burnt-umber-mist);
    margin-top: 1rem;
}

/* Notebook sketches */
.notebook-sketches {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.sketch-item {
    background: rgba(245, 237, 224, 0.3);
    padding: 0.8rem;
    position: relative;
}

.sketch-svg {
    width: 100%;
    height: auto;
}

.sketch-note {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--burnt-umber-mist);
    margin-top: 0.4rem;
}

/* Margin decorations */
.margin-decorations {
    display: flex;
    gap: 3rem;
    margin-top: 2rem;
    opacity: 0.5;
}

/* ============================================
   PAGE 6: THE COLOPHON
   ============================================ */
.page-colophon {
    background-color: var(--charcoal-dusk);
}

.page-inner-colophon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--page-padding);
    padding-left: 4rem;
    position: relative;
}

.colophon-brand {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--saffron-glow);
    position: absolute;
    top: var(--page-padding);
    left: 4rem;
}

.colophon-links {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.colophon-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: var(--parchment-dusk);
    font-family: var(--font-accent);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition: color 0.3s ease;
}

.colophon-link:hover {
    color: var(--saffron-glow);
}

.link-arrow .hand-drawn-line {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    transition: stroke-dashoffset 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.colophon-link:hover .link-arrow .hand-drawn-line {
    stroke-dashoffset: 0;
}

.colophon-link:hover .link-arrow .hand-drawn-line {
    stroke: var(--saffron-glow);
}

.colophon-motif {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
}

.colophon-botanical {
    width: 150px;
    height: 150px;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes drawLine {
    to {
        stroke-dashoffset: 0;
    }
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Staggered cell stroke reveals */
.page.active .cell-stroke:nth-child(1) { transition-delay: 0ms; }
.page.active .cell-stroke:nth-child(2) { transition-delay: 200ms; }
.page.active .cell-stroke:nth-child(3) { transition-delay: 400ms; }
.page.active .cell-stroke:nth-child(4) { transition-delay: 600ms; }
.page.active .cell-stroke:nth-child(5) { transition-delay: 800ms; }
.page.active .cell-stroke:nth-child(6) { transition-delay: 1000ms; }
.page.active .cell-stroke:nth-child(7) { transition-delay: 1200ms; }
.page.active .cell-stroke:nth-child(8) { transition-delay: 1400ms; }
.page.active .cell-stroke:nth-child(9) { transition-delay: 1600ms; }
.page.active .cell-stroke:nth-child(10) { transition-delay: 1800ms; }
.page.active .cell-stroke:nth-child(11) { transition-delay: 2000ms; }
.page.active .cell-stroke:nth-child(12) { transition-delay: 2200ms; }
.page.active .cell-stroke:nth-child(13) { transition-delay: 2400ms; }

.page.active .cell-fade:nth-child(1) { transition-delay: 2000ms; }
.page.active .cell-fade:nth-child(2) { transition-delay: 2200ms; }
.page.active .cell-fade:nth-child(3) { transition-delay: 2400ms; }
.page.active .cell-fade:nth-child(4) { transition-delay: 2600ms; }

/* ============================================
   RESPONSIVE (< 768px)
   ============================================ */
@media (max-width: 768px) {
    .page-inner {
        flex-direction: column;
        padding-left: 3rem;
    }

    .folio,
    .marginalia {
        flex: 0 0 auto;
        max-width: 100%;
        width: 100%;
    }

    .marginalia {
        box-shadow: none;
        padding-left: 1rem;
        padding-top: 1.5rem;
        background: transparent;
    }

    .folio {
        padding-right: 1rem;
    }

    /* Role-reversal page */
    .page-inner-reversed {
        flex-direction: column;
    }

    .folio-narrow {
        flex: 0 0 auto;
        max-width: 100%;
        padding-left: 1rem;
    }

    .marginalia-expanded {
        flex: 0 0 auto;
        max-width: 100%;
        padding-left: 1rem;
    }

    .notebook-sketches {
        grid-template-columns: 1fr;
    }

    #nav-timeline {
        left: 0.5rem;
    }

    .waypoint-label {
        display: none;
    }

    .milestone-card {
        width: 160px;
    }

    .inscription-title {
        font-size: clamp(3rem, 10vw, 5rem);
    }

    .colophon-brand {
        left: 3rem;
    }

    .page-inner-colophon {
        padding-left: 3rem;
    }
}

/* ============================================
   SELECTION & MISC
   ============================================ */
::selection {
    background-color: var(--wheat-glow);
    color: var(--ink-sepia);
}

a {
    color: var(--terracotta-ember);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--saffron-glow);
}

/* Colophon grain override */
.page-colophon::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 300px 300px;
    opacity: 0.04;
    mix-blend-mode: overlay;
}
