/* ============================================
   blockchain.day - Scholarly Codex Aesthetic
   Deep-Burgundy Palette / Luxury-Premium
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-obsidian: #0E0B0D;
    --bg-burgundy: #3B0A1E;
    --bg-claret: #5C1A2E;
    --text-cream: #F0E6D3;
    --text-vellum: #B8A48E;
    --accent-gold: #C4975A;
    --accent-teal: #2A7A6E;
    --glitch-red: #E23D4F;
    --border-brass: #8B6F3E;
    --skyline-dark: #1A0F14;

    --font-heading: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
    --font-display: 'Cormorant Garamond', 'Times New Roman', serif;

    --content-width: 720px;
    --section-padding: clamp(3rem, 8vw, 8rem);
}

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

html {
    scroll-behavior: smooth;
    font-size: 18px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-obsidian);
    color: var(--text-cream);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
}

/* --- Static Grain Overlay --- */
.grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.02;
    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.9' 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;
}

/* --- Scroll Progress Bar --- */
.progress-bar {
    position: fixed;
    right: 0;
    top: 0;
    width: 2px;
    height: 100vh;
    z-index: 999;
    background-color: rgba(59, 10, 30, 0.3);
}

.progress-fill {
    width: 100%;
    height: 0%;
    background: linear-gradient(to bottom, var(--bg-burgundy), var(--accent-gold));
    transition: height 50ms linear;
}

.progress-markers {
    position: absolute;
    top: 0;
    left: -20px;
    width: 20px;
    height: 100%;
}

.progress-marker {
    position: absolute;
    right: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--accent-gold);
    opacity: 0.6;
    writing-mode: horizontal-tb;
}

/* --- Chapter Sections --- */
.chapter {
    position: relative;
    width: 100vw;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--section-padding) 0;
    overflow: hidden;
}

.chapter[data-bg="obsidian"] {
    background-color: var(--bg-obsidian);
}

.chapter[data-bg="burgundy"] {
    background-color: var(--bg-burgundy);
}

.chapter[data-bg="claret"] {
    background-color: var(--bg-claret);
}

/* --- Content Column --- */
.content-column {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 clamp(1.5rem, 4vw, 4rem);
    position: relative;
    z-index: 2;
}

/* --- Hash Watermark --- */
.hash-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-5deg);
    font-family: var(--font-mono);
    font-size: clamp(60px, 10vw, 120px);
    color: var(--text-cream);
    opacity: 0.03;
    white-space: nowrap;
    pointer-events: none;
    z-index: 0;
    letter-spacing: 0.05em;
    user-select: none;
}

/* --- Grid Overlay --- */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background-image:
        linear-gradient(to right, rgba(59, 10, 30, 0.2) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(59, 10, 30, 0.2) 1px, transparent 1px);
    background-size: 48px 48px;
    opacity: 0.2;
}

/* --- Epigraph --- */
.epigraph {
    margin-bottom: 4rem;
    padding-left: 2rem;
    border-left: 2px solid rgba(196, 151, 90, 0.3);
}

.epigraph p {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 300;
    font-size: 24px;
    line-height: 1.6;
    color: var(--text-vellum);
    letter-spacing: 0.01em;
}

/* --- Typography --- */
.hero-title {
    font-family: var(--font-heading);
    font-weight: 900;
    font-size: clamp(3.5rem, 7vw, 7rem);
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--text-cream);
    margin-top: 6rem;
    margin-bottom: 2rem;
    position: relative;
}

.section-heading {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--text-cream);
    margin-top: 6rem;
    margin-bottom: 2rem;
    position: relative;
}

.chapter-body p {
    margin-bottom: 2.5em;
    color: var(--text-cream);
    font-weight: 400;
}

.chapter-body p em {
    color: var(--text-vellum);
    font-style: italic;
}

.monospace-accent {
    font-family: var(--font-mono) !important;
    font-size: 13px !important;
    font-weight: 400;
    letter-spacing: 0.05em;
    color: var(--accent-gold) !important;
    line-height: 1.6;
    word-break: break-all;
    padding: 1.5rem 0;
    border-top: 1px solid rgba(139, 111, 62, 0.2);
    border-bottom: 1px solid rgba(139, 111, 62, 0.2);
}

/* --- Glitch Text Effect --- */
.glitch-text {
    position: relative;
}

.glitch-text.glitching::before,
.glitch-text.glitching::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.glitch-text.glitching::before {
    color: var(--glitch-red);
    z-index: -1;
    animation: glitchShift 200ms steps(2) forwards;
}

.glitch-text.glitching::after {
    color: var(--accent-teal);
    z-index: -1;
    animation: glitchShiftReverse 200ms steps(2) forwards;
}

@keyframes glitchShift {
    0% { transform: translate(-2px, 0); }
    50% { transform: translate(1px, 0); }
    100% { transform: translate(0, 0); }
}

@keyframes glitchShiftReverse {
    0% { transform: translate(2px, 0); }
    50% { transform: translate(-1px, 0); }
    100% { transform: translate(0, 0); }
}

/* --- Section Transitions --- */
.section-transition {
    position: relative;
    height: 160px;
    background: linear-gradient(to bottom, transparent, var(--bg-obsidian));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    margin-top: auto;
}

.chapter[data-bg="burgundy"] .section-transition {
    background: linear-gradient(to bottom, var(--bg-burgundy), var(--bg-obsidian));
}

.chapter[data-bg="claret"] .section-transition {
    background: linear-gradient(to bottom, var(--bg-claret), var(--bg-obsidian));
}

.gold-rule {
    width: 200px;
    height: 1px;
    background-color: rgba(196, 151, 90, 0.4);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.skyline-silhouette {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    opacity: 0.6;
    color: #1A0F14;
}

/* --- Floating Marginalia --- */
.marginalia {
    display: none;
}

@media (min-width: 1400px) {
    .marginalia {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        position: absolute;
        z-index: 3;
    }

    .left-margin {
        left: calc(50% - 360px - 280px);
        top: 40%;
    }

    .marginalia-text {
        font-family: var(--font-mono);
        font-size: 11px;
        color: var(--accent-gold);
        opacity: 0.4;
        letter-spacing: 0.05em;
        white-space: nowrap;
        position: relative;
    }

    .marginalia-text::before {
        content: '';
        position: absolute;
        top: 50%;
        right: -20px;
        width: 16px;
        height: 1px;
        background-color: rgba(196, 151, 90, 0.2);
    }
}

/* --- Neon Fragments --- */
.neon-fragment {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.3em;
    color: var(--accent-teal);
    text-shadow: 0 0 8px rgba(42, 122, 110, 0.5);
    opacity: 0;
    z-index: 3;
    pointer-events: none;
    transition: opacity 2s ease-in-out;
    animation: neonPulse 3s ease-in-out infinite;
}

.neon-fragment.visible {
    opacity: 0.8;
}

.neon-right {
    right: clamp(1rem, 3vw, 4rem);
}

.neon-left {
    left: clamp(1rem, 3vw, 4rem);
}

@keyframes neonPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1.0; }
}

.neon-fragment.visible {
    animation: neonPulseVisible 3s ease-in-out infinite;
}

@keyframes neonPulseVisible {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1.0; }
}

/* --- Network Diagram --- */
.network-diagram {
    margin: 3rem auto;
    max-width: 600px;
}

.topology-svg {
    width: 100%;
    height: auto;
    opacity: 0.6;
}

/* --- Gilt Corner Frame --- */
.gilt-frame {
    position: relative;
    padding: 3rem;
    margin: 4rem 0;
}

.gilt-corner {
    position: absolute;
    width: 40px;
    height: 40px;
}

.gilt-top-left { top: 0; left: 0; }
.gilt-top-right { top: 0; right: 0; }
.gilt-bottom-left { bottom: 0; left: 0; }
.gilt-bottom-right { bottom: 0; right: 0; }

.gilt-frame-content {
    text-align: center;
}

.gilt-frame-content .monospace-accent {
    border: none;
    padding: 0;
    font-size: 14px !important;
    line-height: 1.8;
}

/* --- Scale Hover Interactions --- */
.gilt-frame,
.epigraph {
    transition: transform 400ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 400ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.gilt-frame:hover,
.epigraph:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* --- Scroll-Triggered Text Reveals --- */
.chapter-body p,
.epigraph,
.section-heading,
.hero-title,
.network-diagram,
.gilt-frame {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease-out, transform 600ms ease-out;
}

.chapter-body p.revealed,
.epigraph.revealed,
.section-heading.revealed,
.hero-title.revealed,
.network-diagram.revealed,
.gilt-frame.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* --- Scan-line Overlay on Images/Diagrams --- */
.network-diagram::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: repeating-linear-gradient(
        to bottom,
        rgba(14, 11, 13, 0.15) 0px,
        rgba(14, 11, 13, 0.15) 1px,
        transparent 1px,
        transparent 3px
    );
    z-index: 1;
}

.network-diagram {
    position: relative;
}

/* --- Colophon / Footer --- */
.colophon {
    padding: 6rem 0;
    text-align: center;
    background-color: var(--bg-obsidian);
    border-top: 1px solid rgba(139, 111, 62, 0.15);
}

.colophon-text {
    font-family: var(--font-heading);
    font-weight: 400;
    font-size: clamp(1.5rem, 3vw, 2rem);
    color: var(--text-vellum);
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.colophon-hash {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent-gold);
    opacity: 0.4;
    letter-spacing: 0.05em;
}

/* --- Channel Displacement Effect (Glitch Art) --- */
.chapter::before {
    content: '';
    position: absolute;
    top: 0;
    left: 3px;
    width: 100%;
    height: 100%;
    background: inherit;
    mix-blend-mode: screen;
    opacity: 0;
    pointer-events: none;
    z-index: 0;
    filter: hue-rotate(-60deg) saturate(2);
}

.chapter.channel-glitch::before {
    opacity: 0.03;
    animation: channelDisplace 200ms steps(3) forwards;
}

@keyframes channelDisplace {
    0% { transform: translateX(4px); opacity: 0.05; }
    33% { transform: translateX(-2px); opacity: 0.03; }
    66% { transform: translateX(1px); opacity: 0.04; }
    100% { transform: translateX(0); opacity: 0; }
}

/* --- Responsive adjustments --- */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    .epigraph p {
        font-size: 20px;
    }

    .hash-watermark {
        font-size: 40px;
    }

    .chapter {
        padding: clamp(2rem, 6vw, 4rem) 0;
    }

    .neon-fragment {
        font-size: 10px;
        letter-spacing: 0.2em;
    }

    .gilt-frame {
        padding: 2rem;
        margin: 2rem 0;
    }
}

@media (max-width: 480px) {
    .hero-title {
        margin-top: 3rem;
    }

    .section-heading {
        margin-top: 3rem;
    }

    .epigraph {
        padding-left: 1rem;
    }

    .network-diagram {
        margin: 2rem auto;
    }
}
