/* ============================================
   op9.rs - The Candlelit Codex
   Ethereal Monastic Tech Design
   ============================================ */

/* === CSS Custom Properties === */
:root {
    --forge-night: #1a0f07;
    --umber-shadow: #2a1a0e;
    --terracotta-flame: #c4713b;
    --amber-glow: #d4a574;
    --candlelight: #e8c9a0;
    --molten-copper: #b8562e;
    --dark-umber: #6b4c35;
    --parchment: #f2e6d4;
    --muted-brown: #8b5e3c;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background: var(--forge-night);
    color: var(--candlelight);
    font-family: 'EB Garamond', Georgia, serif;
    font-size: clamp(1.1rem, 1.8vw, 1.35rem);
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
}

/* === Parchment Texture Overlay === */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* === Navigation Dots === */
#nav-dots {
    position: fixed;
    right: 2vw;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.nav-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dark-umber);
    cursor: pointer;
    transition: transform 0.3s ease-out, box-shadow 0.3s ease-out, opacity 0.3s ease-out;
    opacity: 0.3;
}

.nav-dot.active {
    opacity: 1;
    box-shadow: 0 0 8px var(--terracotta-flame);
    background: var(--terracotta-flame);
}

.nav-dot:hover {
    transform: scale(1.25);
}

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

/* === Bokeh Background === */
.bokeh-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.bokeh-circle {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(196, 113, 59, 0.15) 0%, transparent 70%);
    filter: blur(20px);
    animation: drift 12s ease-in-out infinite alternate;
    will-change: transform, opacity;
}

@keyframes drift {
    0% { transform: translate(0, 0); opacity: 0.12; }
    25% { transform: translate(15px, -10px); opacity: 0.18; }
    50% { transform: translate(-10px, 20px); opacity: 0.14; }
    75% { transform: translate(20px, 10px); opacity: 0.16; }
    100% { transform: translate(-15px, -15px); opacity: 0.12; }
}

/* === Ember Particles === */
.ember-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.ember {
    position: absolute;
    bottom: -10px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--terracotta-flame);
    opacity: 0.3;
    animation: ember-rise 10s linear infinite;
    will-change: transform, opacity;
}

@keyframes ember-rise {
    0% { transform: translateY(0) scale(1); opacity: 0.3; }
    50% { opacity: 0.2; }
    100% { transform: translateY(-100vh) scale(0.5); opacity: 0; }
}

/* === Candle Flame === */
.flame {
    width: 14px;
    height: 36px;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    background: radial-gradient(ellipse at 50% 90%, #f2e6d4 0%, #c4713b 40%, #b8562e 70%, transparent 100%);
    animation: flicker 3s ease-in-out infinite alternate;
    filter: blur(0.5px);
    will-change: transform, opacity;
}

@keyframes flicker {
    0% { transform: scaleX(0.85) rotate(-3deg); opacity: 0.7; }
    20% { transform: scaleX(1.05) rotate(1deg); opacity: 0.9; }
    40% { transform: scaleX(0.95) rotate(-2deg); opacity: 0.8; }
    60% { transform: scaleX(1.1) rotate(2deg); opacity: 1; }
    80% { transform: scaleX(0.9) rotate(-1deg); opacity: 0.85; }
    100% { transform: scaleX(1.15) rotate(3deg); opacity: 1; }
}

/* === Hero Chapter === */
.hero-chapter {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--forge-night);
}

.hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
    opacity: 0;
    animation: hero-fade-in 1.5s ease-out 0.3s forwards;
}

@keyframes hero-fade-in {
    to { opacity: 1; }
}

.hero-flame-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.hero-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(4rem, 10vw, 8rem);
    color: var(--parchment);
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 0.5rem;
}

.hero-rs {
    color: var(--parchment);
}

.hero-subtitle {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    color: var(--amber-glow);
    font-weight: 400;
}

.scroll-chevron {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    animation: chevron-pulse 2s ease-in-out infinite;
    animation-delay: 2s;
    opacity: 0;
}

@keyframes chevron-pulse {
    0%, 100% { opacity: 0.4; transform: translateX(-50%) translateY(0); }
    50% { opacity: 0.8; transform: translateX(-50%) translateY(8px); }
}

/* === Breathing Spaces === */
.breathing-space {
    height: 20vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #1a0f07 0%, #2a1a0e 50%, #1a0f07 100%);
    position: relative;
}

.breathing-flame {
    position: relative;
    z-index: 1;
}

/* === Z-Section Layout === */
.z-section {
    background: var(--umber-shadow);
    padding: clamp(3rem, 6vw, 6rem) clamp(2rem, 4vw, 4rem);
}

.z-section:nth-child(odd) {
    background: var(--forge-night);
}

.z-content {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    gap: clamp(2rem, 4vw, 5rem);
    max-width: 1200px;
    margin: 0 auto;
    min-height: 70vh;
    align-items: center;
}

.z-stroke-1 {
    grid-column: 1 / -1;
    justify-self: start;
    max-width: 80%;
}

.z-stroke-3 {
    grid-column: 1 / -1;
    justify-self: end;
    max-width: 80%;
    margin-left: 20vw;
}

.z-heading {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--terracotta-flame);
    letter-spacing: 0.02em;
    line-height: 1.25;
}

.z-heading-large {
    font-weight: 600;
    font-style: normal;
    font-size: clamp(2.8rem, 6vw, 5.5rem);
}

/* === Z-Diagonal SVG === */
.z-diagonal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.z-diagonal line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.8s ease-out;
}

.z-section.visible .z-diagonal line {
    stroke-dashoffset: 0;
}

/* === Wax Seal === */
.wax-seal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: radial-gradient(circle, #b8562e, #8b5e3c);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--parchment);
    z-index: 2;
    transition: transform 0.3s ease-out;
}

.wax-seal:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

/* === Code Blocks === */
.code-block {
    background: var(--forge-night);
    border-left: 3px solid var(--terracotta-flame);
    padding: 2rem;
    border-radius: 4px;
    overflow-x: auto;
    transition: transform 0.3s ease-out, box-shadow 0.3s ease-out;
}

.code-block:hover {
    transform: scale(1.01);
    box-shadow: 0 4px 20px rgba(196, 113, 59, 0.1);
}

.code-block pre {
    margin: 0;
}

.code-block code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.9rem, 1.4vw, 1.1rem);
    font-weight: 400;
    line-height: 1.6;
    color: var(--candlelight);
}

/* Syntax Highlighting */
.code-block .kw { color: #c4713b; font-weight: 600; }
.code-block .fn-name { color: #e8c9a0; }
.code-block .str { color: #d4a574; }
.code-block .comment { color: #6b4c35; font-style: italic; }
.code-block .hi { color: #b8562e; font-weight: 600; }

/* === Diagonal Flame Paths (Chapter III) === */
.z-diagonal-flames {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.path-flame {
    position: absolute;
}

.flame-path-1 {
    animation: flame-travel-1 6s ease-in-out infinite;
}

.flame-path-2 {
    animation: flame-travel-2 6s ease-in-out infinite;
}

@keyframes flame-travel-1 {
    0% { top: 15%; left: 75%; opacity: 0.6; }
    50% { top: 50%; left: 50%; opacity: 0.9; }
    100% { top: 85%; left: 25%; opacity: 0.6; }
}

@keyframes flame-travel-2 {
    0% { top: 85%; left: 25%; opacity: 0.6; }
    50% { top: 50%; left: 50%; opacity: 0.9; }
    100% { top: 15%; left: 75%; opacity: 0.6; }
}

/* === Concurrency Flames (Chapter IV) === */
.concurrency-flames {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: clamp(1rem, 3vw, 3rem);
    z-index: 1;
    pointer-events: none;
    opacity: 0.4;
}

/* === Final Chapter === */
.final-chapter .bokeh-circle {
    transition: opacity 3s ease-out;
}

.final-chapter.brightened .bokeh-circle {
    opacity: 0.25 !important;
}

.prose-conclusion {
    font-family: 'EB Garamond', Georgia, serif;
    font-size: 1.4rem;
    line-height: 1.8;
    color: var(--candlelight);
    max-width: 600px;
}

.prose-conclusion em {
    color: var(--amber-glow);
    font-style: italic;
}

/* === Colophon === */
.colophon {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1rem;
    color: var(--dark-umber);
    letter-spacing: 0.05em;
    z-index: 1;
}

/* === Dense Bokeh (Chapter IV) === */
.dense-bokeh .bokeh-circle {
    background: radial-gradient(circle, rgba(196, 113, 59, 0.2) 0%, transparent 70%);
}

/* === Final Embers (Chapter V) === */
.final-embers .ember {
    opacity: 0.4;
    width: 5px;
    height: 5px;
}

/* === Responsive === */
@media (max-width: 768px) {
    .z-stroke-3 {
        margin-left: 5vw;
        max-width: 95%;
    }

    .z-stroke-1 {
        max-width: 95%;
    }

    .z-content {
        grid-template-columns: 1fr;
    }

    .concurrency-flames {
        gap: 0.8rem;
    }

    .concurrency-flames .flame {
        width: 10px;
        height: 26px;
    }

    #nav-dots {
        right: 1vw;
    }

    .prose-conclusion {
        font-size: 1.15rem;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: clamp(3rem, 15vw, 5rem);
    }

    .z-heading {
        font-size: clamp(1.5rem, 5vw, 2.5rem);
    }

    .code-block {
        padding: 1rem;
    }

    .code-block code {
        font-size: 0.85rem;
    }
}