/* ============================================
   transactology.org — Styles
   Palette: Muted-Vintage
   Typography: Space Grotesk / DM Sans / IBM Plex Mono
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --aged-vellum: #F2EDE4;
    --smoked-linen: #E3DCD0;
    --carbon-ink: #2B2926;
    --ledger-gray: #7A756C;
    --oxidized-copper: #B07B5F;
    --tarnished-dime: #8B9EA7;
    --vault-slate: #3D3B38;
    --faded-receipt: #D4C9B5;
    --scroll-progress: 0;
    --chapter-progress: 0;
}

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

html {
    scroll-behavior: smooth;
    scrollbar-width: none;
}

html::-webkit-scrollbar {
    display: none;
}

body {
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.75;
    color: var(--carbon-ink);
    background-color: var(--aged-vellum);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.03;
}

#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-repeat: repeat;
}

/* --- Scroll Progress Indicator --- */
#scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 20px;
    height: 100vh;
    z-index: 999;
    pointer-events: none;
}

#progress-wave {
    width: 100%;
    height: 100%;
}

#progress-line {
    position: absolute;
    top: 0;
    left: 10px;
    width: 1px;
    height: 0%;
    background: var(--oxidized-copper);
    transition: height 0.1s linear;
}

/* --- Chapter Base --- */
.chapter {
    position: relative;
    min-height: 200vh;
    overflow: hidden;
}

.chapter-final {
    min-height: 100vh;
}

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

/* --- Chapter Pin Mechanic --- */
.chapter-pin {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    pointer-events: none;
}

.chapter-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(2.8rem, 7vw, 5.2rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--carbon-ink);
    transition: opacity 0.8s ease-out, color 1.2s ease-out;
}

.chapter-title.faded {
    color: var(--ledger-gray);
    opacity: 0.3;
}

/* --- Chapter Body --- */
.chapter-body {
    position: relative;
    z-index: 3;
    padding: 10vh 0;
}

/* --- Chapter 1: The Word --- */
#chapter-1 {
    min-height: 250vh;
}

.chapter-1-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        135deg,
        var(--aged-vellum) 0%,
        var(--smoked-linen) 40%,
        var(--faded-receipt) 70%,
        var(--aged-vellum) 100%
    );
    opacity: 0.2;
}

.chapter-1-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 5vh;
}

.etymology {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 0.5em;
    margin-bottom: 2rem;
    padding: 0 6vw;
}

.etymology-part {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--oxidized-copper);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.etymology-plus,
.etymology-equals {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    color: var(--ledger-gray);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.etymology-meaning {
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    color: var(--carbon-ink);
    font-style: italic;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

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

.annotation {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--ledger-gray);
    text-align: center;
    padding: 0 6vw;
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

.annotation.visible {
    opacity: 1;
}

/* --- Chapter 2: The Exchange --- */
.chapter-2-body {
    padding-left: 15vw;
    padding-right: 6vw;
}

.exchange-animation {
    width: 100%;
    max-width: 600px;
    margin: 0 auto 6vh;
}

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

.two-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4vw;
    max-width: 80ch;
}

.column p {
    max-width: 55ch;
    margin-bottom: 1.5em;
    color: var(--carbon-ink);
}

.wave-bg-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    opacity: 0.04;
    background-image: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 40px,
        var(--faded-receipt) 40px,
        var(--faded-receipt) 41px
    );
}

/* --- Chapter 3: The Ledger (Dark) --- */
.chapter-dark {
    background-color: var(--vault-slate);
    color: var(--aged-vellum);
}

.chapter-dark .chapter-title {
    color: var(--aged-vellum);
}

.chapter-dark .chapter-title.faded {
    color: var(--ledger-gray);
    opacity: 0.3;
}

.chapter-3-body {
    padding-left: 15vw;
    padding-right: 6vw;
}

.ledger-waterfall {
    margin-bottom: 6vh;
}

.ledger-entry {
    display: flex;
    gap: 2em;
    align-items: baseline;
    padding: 1em 0;
    border-bottom: 1px solid rgba(212, 201, 181, 0.15);
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.ledger-entry.visible {
    opacity: 1;
    transform: translateX(0);
}

.ledger-timestamp {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--tarnished-dime);
    white-space: nowrap;
    min-width: 10ch;
}

.ledger-text {
    font-family: 'DM Sans', sans-serif;
    font-size: clamp(0.9rem, 1.1vw, 1.05rem);
    color: var(--aged-vellum);
    max-width: 55ch;
}

.chapter-3-text {
    max-width: 55ch;
}

.chapter-3-text p {
    margin-bottom: 1.5em;
    color: var(--smoked-linen);
}

/* --- Chapter 4: The Current --- */
.chapter-4-body {
    padding-left: 15vw;
    padding-right: 6vw;
}

.current-wave-container {
    position: relative;
    width: 100%;
    height: 40vh;
    margin-bottom: 4vh;
    overflow: hidden;
}

.current-wave-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.chapter-4-text {
    max-width: 55ch;
}

.chapter-4-text p {
    margin-bottom: 1.5em;
}

/* --- Chapter 5: The Silence After --- */
.chapter-final {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 10vh 0;
}

.chapter-5-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 6vw;
}

.final-text {
    max-width: 40ch;
    text-align: center;
    margin-bottom: 8vh;
}

.final-text p {
    margin-bottom: 1.5em;
    color: var(--carbon-ink);
}

.final-receipt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5em;
    padding: 3em 4em;
    background-color: var(--smoked-linen);
    border: 1px solid var(--faded-receipt);
}

.receipt-line {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--ledger-gray);
}

.receipt-timestamp {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--tarnished-dime);
}

.receipt-divider {
    color: var(--faded-receipt);
    letter-spacing: 0.12em;
}

.receipt-total {
    color: var(--carbon-ink);
    font-weight: 400;
}

/* --- Wave Transitions --- */
.wave-transition {
    position: relative;
    height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--aged-vellum);
}

#wave-transition-2 {
    background-color: var(--aged-vellum);
}

#wave-transition-3 {
    background-color: var(--vault-slate);
}

.wave-svg {
    width: 100%;
    height: 200px;
}

/* --- Lens Flare Effects --- */
.lens-flare {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    mix-blend-mode: screen;
    transition: transform 0.3s ease-out;
}

.flare-1 {
    width: 300px;
    height: 300px;
    top: 20%;
    right: 10%;
    background: radial-gradient(circle, rgba(176, 123, 95, 0.25) 0%, transparent 70%);
}

.flare-2 {
    width: 200px;
    height: 200px;
    bottom: 30%;
    left: 5%;
    background: radial-gradient(circle, rgba(139, 158, 167, 0.2) 0%, transparent 70%);
}

.flare-3 {
    width: 250px;
    height: 250px;
    top: 40%;
    right: 15%;
    background: radial-gradient(circle, rgba(176, 123, 95, 0.2) 0%, transparent 70%);
}

.flare-4 {
    width: 350px;
    height: 350px;
    top: 15%;
    left: 60%;
    background: radial-gradient(circle, rgba(139, 158, 167, 0.15) 0%, transparent 70%);
}

.flare-5 {
    width: 400px;
    height: 400px;
    top: 10%;
    right: 5%;
    background: radial-gradient(circle, rgba(176, 123, 95, 0.3) 0%, transparent 70%);
}

.flare-6 {
    width: 250px;
    height: 250px;
    bottom: 20%;
    left: 10%;
    background: radial-gradient(circle, rgba(176, 123, 95, 0.2) 0%, transparent 70%);
}

/* --- Horizontal Ruled Lines (Ledger) --- */
.chapter-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--faded-receipt);
}

/* --- Reveal Animation --- */
.reveal-up {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0),
                transform 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.reveal-up.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Halftone Hover Effect --- */
.final-receipt:hover {
    background-image: radial-gradient(circle, var(--faded-receipt) 1px, transparent 1px);
    background-size: 4px 4px;
}

/* --- Progress indicator color change in dark sections --- */
body.in-dark-chapter #progress-path {
    stroke: var(--tarnished-dime);
}

body.in-dark-chapter #progress-line {
    background: var(--tarnished-dime);
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .chapter-2-body,
    .chapter-3-body,
    .chapter-4-body {
        padding-left: 6vw;
        padding-right: 6vw;
    }

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

    .chapter-title {
        font-size: clamp(2rem, 8vw, 3.5rem);
    }

    .etymology {
        flex-direction: column;
        align-items: center;
        gap: 0.3em;
    }

    .exchange-animation {
        margin-bottom: 4vh;
    }

    .ledger-entry {
        flex-direction: column;
        gap: 0.5em;
    }

    .final-receipt {
        padding: 2em;
    }

    .flare-1, .flare-2, .flare-3,
    .flare-4, .flare-5, .flare-6 {
        display: none;
    }

    .current-wave-container {
        height: 25vh;
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    .chapter-title,
    .etymology-part,
    .etymology-plus,
    .etymology-equals,
    .etymology-meaning,
    .annotation,
    .ledger-entry,
    .reveal-up {
        transition: opacity 0.01s !important;
        transform: none !important;
    }

    .reveal-up.visible,
    .ledger-entry.visible,
    .etymology .visible,
    .annotation.visible {
        opacity: 1;
        transform: none;
    }
}
