/* ==========================================================================
   chloengine.com — a forbidden codex from an alternate 1970s
   Colors:
     #0b0c10  Void / Deep Obsidian (primary background)
     #e8dcc8  Parchment Bone (primary text)
     #d4a843  Amber Glow (accent primary, annotations)
     #4355d4  Twilight Indigo (interactive elements / links)
     #5a8a7a  Faded Verdigris (marginalia / oscilloscope)
     #2a2d35  Graphite Trace (rules, circuit art)
     #f5e6c8  Incandescent Cream (hover / active)
     #8b4a3a  Rust Oxide (struck-through)
   Fonts: Playfair Display (Google Fonts), Source Serif 4 (Google Fonts), IBM Plex Mono, Cormorant Garamond
   Interface Metaphor: Metaphor* Metaphor:: Metaphor::* Metaphor:** The entire page is structured as a scholarly manuscript — frontispiece
   IntersectionObserver transitions use IntersectionObserver` with `threshold: 0.15` on each `<section>`. When a section enters the viewport
   ========================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    min-height: 100%;
    background: #0b0c10;
    color: #e8dcc8;
    font-family: "Source Serif 4", Georgia, serif;
    font-size: 16px;
    line-height: 1.85;
    font-feature-settings: "onum" 1, "liga" 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body {
    position: relative;
}

a {
    color: #4355d4;
    text-decoration: none;
    border-bottom: 1px solid rgba(67, 85, 212, 0.35);
    transition: color 0.5s ease, border-color 0.5s ease, background 0.5s ease;
}

a:hover {
    color: #f5e6c8;
    border-bottom-color: #d4a843;
    background: rgba(212, 168, 67, 0.06);
}

/* --------------------------------------------------------------------------
   Particle canvas — living margins behind the codex
   -------------------------------------------------------------------------- */
#particle-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    display: block;
}

/* --------------------------------------------------------------------------
   Page-edge gutter shadows (shadowed book-gutter effect)
   -------------------------------------------------------------------------- */
.gutter-shadow {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 12vw;
    max-width: 220px;
    pointer-events: none;
    z-index: 1;
}
.gutter-left {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.55), rgba(0,0,0,0));
}
.gutter-right {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.55), rgba(0,0,0,0));
}

/* --------------------------------------------------------------------------
   Codex main column — strict single-column narrative descent
   -------------------------------------------------------------------------- */
.codex {
    position: relative;
    z-index: 2;
    max-width: 680px;
    margin: 0 auto;
    padding: 0 24px 120px;
}

/* --------------------------------------------------------------------------
   Frontispiece — hero
   -------------------------------------------------------------------------- */
.frontispiece {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 80px 0 60px;
    position: relative;
}

.frontispiece-inner {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 40px;
    align-items: flex-start;
}

.engine-name {
    font-family: "Playfair Display", Georgia, serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 8vw, 5.5rem);
    letter-spacing: -0.03em;
    line-height: 1;
    color: #e8dcc8;
    display: inline-block;
    word-break: break-word;
}

.engine-name .letter {
    display: inline-block;
    opacity: 0;
    transform-origin: center;
    will-change: transform, opacity;
    animation: assemble 0.9s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes assemble {
    0%   { opacity: 0; }
    60%  { opacity: 0.55; }
    100% { opacity: 1; transform: translate(0, 0) rotate(0); }
}

.subline {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-weight: 400;
    font-size: 0.875rem;
    color: #d4a843;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 1.4em;
    padding-left: 2px;
    border-left: 1px solid rgba(212, 168, 67, 0.25);
    padding-left: 10px;
}

.subline-text { white-space: pre; }

.caret {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 3px;
    background: #d4a843;
    animation: blink 1s steps(2, end) infinite;
}

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

.frontispiece-sigil {
    opacity: 0.85;
    margin-top: 10px;
}
.frontispiece-sigil svg {
    display: block;
    filter: drop-shadow(0 0 18px rgba(212, 168, 67, 0.12));
}

.scroll-hint {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.72rem;
    color: #5a8a7a;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 40px;
    opacity: 0;
    animation: fade-in 2s 3.2s forwards;
}

.scroll-hint-line {
    width: 60px;
    height: 1px;
    background: linear-gradient(to right, #5a8a7a, transparent);
    display: inline-block;
}

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

/* --------------------------------------------------------------------------
   Chapter shared styles (fog-like transitions via IntersectionObserver)
   -------------------------------------------------------------------------- */
.chapter {
    padding: 100px 0 60px;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.2s cubic-bezier(0.16, 1, 0.3, 1),
                transform 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.chapter-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding-bottom: 36px;
    margin-bottom: 30px;
    border-bottom: 1px solid #2a2d35;
}

.chapter-numeral {
    font-family: "Cormorant Garamond", "Playfair Display", serif;
    font-weight: 300;
    font-size: 3rem;
    letter-spacing: 0.15em;
    color: #d4a843;
    line-height: 1;
}

.chapter-title {
    font-family: "Playfair Display", Georgia, serif;
    font-weight: 600;
    font-size: 1.75rem;
    letter-spacing: -0.03em;
    color: #e8dcc8;
    line-height: 1.1;
}

.chapter-subtitle {
    font-family: "IBM Plex Mono", monospace;
    font-weight: 300;
    font-size: 0.8125rem;
    color: #5a8a7a;
    letter-spacing: 0.05em;
    font-style: italic;
}

.chapter-body {
    font-size: 1.125rem;
    line-height: 1.85;
    color: #e8dcc8;
}

.chapter-body p {
    position: relative;
    margin-bottom: 1.6em;
    text-indent: -1.5em;
    padding-left: 1.5em;
}

.italic-body p {
    font-style: italic;
}

.italic-body em.correction {
    font-style: normal;
}

/* Drop caps for the first paragraph of each chapter */
.with-dropcap::first-letter {
    font-family: "Cormorant Garamond", "Playfair Display", serif;
    font-size: 4rem;
    font-weight: 400;
    float: left;
    line-height: 0.8;
    padding: 0.18em 0.5rem 0 0;
    color: #d4a843;
    border-bottom: 2px solid #d4a843;
    margin-right: 6px;
}

/* Margin notes — absolute positioning on wide viewports */
.margin-note {
    display: block;
    position: absolute;
    right: -240px;
    top: 0;
    width: 200px;
    padding: 6px 0 6px 12px;
    border-left: 1px solid #2a2d35;
    font-family: "IBM Plex Mono", monospace;
    font-weight: 300;
    font-size: 0.75rem;
    color: #5a8a7a;
    text-indent: 0;
    line-height: 1.55;
    letter-spacing: 0.02em;
    font-style: normal;
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 1.2s cubic-bezier(0.16, 1, 0.3, 1),
                transform 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.chapter.visible .margin-note {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 0.3s;
}

.mn-label {
    display: block;
    color: #d4a843;
    letter-spacing: 0.1em;
    margin-bottom: 6px;
    font-size: 0.7rem;
    text-transform: lowercase;
}
.mn-body { display: block; }

/* Revised text (struck-through with correction above) */
.revised {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.1;
    vertical-align: baseline;
    margin: 0 2px;
    position: relative;
    top: 0.15em;
}
.revised s {
    color: #8b4a3a;
    text-decoration: line-through;
    text-decoration-color: rgba(139, 74, 58, 0.7);
    font-size: 0.85em;
    order: 2;
    opacity: 0.75;
    transition: opacity 0.6s ease;
}
.revised em.correction {
    order: 1;
    color: #d4a843;
    font-size: 0.82em;
    font-style: normal;
    letter-spacing: 0.02em;
    padding: 0 0.2em;
    margin-bottom: 2px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.9s ease, transform 0.9s ease;
}

.chapter.visible .revised em.correction {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.5s;
}

/* Footnote superscript markers */
.footnote-marker {
    display: inline-block;
    margin-left: 2px;
    padding: 0 3px;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.6em;
    color: #d4a843;
    cursor: help;
    border-bottom: 1px dotted #d4a843;
    font-style: normal;
    text-indent: 0;
    vertical-align: super;
    line-height: 1;
    transition: color 0.3s ease, background 0.3s ease;
}
.footnote-marker:hover {
    color: #f5e6c8;
    background: rgba(212, 168, 67, 0.1);
}

/* Tooltip (for footnotes) */
.tooltip {
    position: fixed;
    z-index: 1000;
    max-width: 260px;
    padding: 10px 14px;
    background: #0b0c10;
    border: 1px solid #2a2d35;
    border-left: 2px solid #d4a843;
    color: #e8dcc8;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    letter-spacing: 0.02em;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}
.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Concordance (chapter II) — entries
   -------------------------------------------------------------------------- */
.concordance-entry {
    margin: 40px 0;
    position: relative;
}

.entry-numeral {
    display: inline-block;
    font-family: "Cormorant Garamond", "Playfair Display", serif;
    font-weight: 300;
    font-size: 1.4rem;
    letter-spacing: 0.15em;
    color: #d4a843;
    margin-bottom: 10px;
}

.entry-title {
    font-family: "Playfair Display", Georgia, serif;
    font-weight: 600;
    font-size: 1.375rem;
    color: #e8dcc8;
    letter-spacing: -0.02em;
    margin-bottom: 14px;
    line-height: 1.25;
}

.entry-body {
    font-size: 1.0625rem;
    line-height: 1.8;
    color: #e8dcc8;
}

/* --------------------------------------------------------------------------
   Oscilloscope dividers (Lissajous)
   -------------------------------------------------------------------------- */
.oscillo-divider {
    margin: 60px 0;
    width: 100%;
    height: 60px;
    opacity: 0.85;
}
.oscillo-divider.small {
    margin: 28px 0;
    height: 50px;
}
.oscillo-divider svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}
.oscillo-divider path {
    fill: none;
    stroke: #5a8a7a;
    stroke-opacity: 0.6;
    stroke-width: 1.5;
    stroke-linecap: round;
}

/* --------------------------------------------------------------------------
   Grimoire diagrams (L-system circuit patterns)
   -------------------------------------------------------------------------- */
.grimoire-diagram {
    width: 100%;
    height: 220px;
    margin: 40px 0;
    position: relative;
    border-top: 1px solid #2a2d35;
    border-bottom: 1px solid #2a2d35;
    padding: 12px 0;
    text-indent: 0;
}
.grimoire-diagram svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}
.grimoire-diagram path {
    fill: none;
    stroke: #2a2d35;
    stroke-width: 1;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.grimoire-diagram circle {
    fill: #2a2d35;
}
.grimoire-diagram .node-terminal {
    fill: #d4a843;
}
.grimoire-diagram .trace-accent {
    stroke: #d4a843;
    stroke-opacity: 0.35;
}

/* --------------------------------------------------------------------------
   Colophon
   -------------------------------------------------------------------------- */
.colophon {
    margin-top: 120px;
    padding: 80px 0 40px;
    border-top: 1px solid #2a2d35;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.2s cubic-bezier(0.16, 1, 0.3, 1),
                transform 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.colophon.visible {
    opacity: 1;
    transform: translateY(0);
}

.colophon-sigil svg {
    display: block;
    opacity: 0.9;
    filter: drop-shadow(0 0 14px rgba(212, 168, 67, 0.1));
}

.colophon-line {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.8125rem;
    color: #5a8a7a;
    letter-spacing: 0.15em;
    text-transform: lowercase;
    text-indent: 0;
    padding-left: 0;
    margin: 0;
}

#colophon-sign {
    color: #d4a843;
    font-size: 1rem;
    padding: 0 4px;
}

.colophon-citation {
    font-family: "Source Serif 4", Georgia, serif;
    font-style: italic;
    font-size: 0.95rem;
    color: #e8dcc8;
    text-indent: 0;
    padding-left: 0;
    margin: 0;
}

.colophon-link {
    color: #4355d4;
    border-bottom-color: rgba(67, 85, 212, 0.4);
}

.colophon-date {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    color: #2a2d35;
    text-transform: uppercase;
    margin-top: 10px;
    text-indent: 0;
    padding-left: 0;
}

/* --------------------------------------------------------------------------
   Responsive — collapse margin notes into inline footnotes on narrow screens
   -------------------------------------------------------------------------- */
@media (max-width: 1100px) {
    .margin-note {
        position: static;
        width: auto;
        right: auto;
        top: auto;
        display: block;
        margin: 14px 0 18px 1.5em;
        padding: 8px 0 8px 14px;
        border-left: 1px solid #2a2d35;
        font-size: 0.75rem;
    }
    .chapter-body p {
        position: static;
    }
    .gutter-shadow { width: 6vw; }
}

@media (max-width: 700px) {
    html, body { font-size: 15px; }
    .codex { padding: 0 18px 80px; }
    .chapter { padding: 70px 0 40px; }
    .chapter-numeral { font-size: 2.3rem; }
    .chapter-title { font-size: 1.45rem; }
    .entry-title { font-size: 1.2rem; }
    .chapter-body { font-size: 1rem; }
    .entry-body { font-size: 0.98rem; }
    .with-dropcap::first-letter { font-size: 3.2rem; }
    .frontispiece { padding: 60px 0 40px; }
    .gutter-shadow { display: none; }
    .oscillo-divider { margin: 40px 0; }
    .grimoire-diagram { height: 160px; }
}

@media (max-width: 440px) {
    .engine-name { font-size: clamp(2rem, 12vw, 3rem); }
    .subline { font-size: 0.78rem; }
}
