/* ============================================================
   TYPOGRAPHY FOUNDATION
   ============================================================ */

:root {
    /* Colors */
    --color-void: #060C18;
    --color-interstitial: #0B1120;
    --color-code-bg: #0D1825;
    --color-card: #0F1A2E;
    --color-diagram: #6BA4D9;
    --color-title: #C8DDF0;
    --color-body: #A0B8D0;
    --color-annotation: #5A7A96;
    --color-hover: #8BC4F0;
    --color-accent: #3D7AB8;
    --color-divider: #1E3350;
    --color-navy: #1A2A40;

    /* Fonts */
    --font-geometric: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Sizing */
    --content-width: 720px;
    --content-width-percent: 55%;
    --nav-height: 48px;
    --annotation-width: 180px;
    --annotation-offset: 40px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--color-void);
    color: var(--color-body);
    font-family: var(--font-body);
    font-size: 19px;
    line-height: 1.72;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeSpeed;
    overflow-x: hidden;
}

/* ============================================================
   BOKEH CANVAS BACKGROUND
   ============================================================ */

#bokeh-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    filter: blur(2px);
    pointer-events: none;
}

/* ============================================================
   NAVIGATION INDEX BAR
   ============================================================ */

.index-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background-color: rgba(6, 12, 24, 0.95);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    border-bottom: 1px solid rgba(110, 164, 217, 0.1);
}

.index-brand {
    font-family: var(--font-geometric);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-title);
}

.index-chapters {
    display: flex;
    gap: 28px;
    align-items: center;
}

.chapter-link {
    font-family: var(--font-geometric);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-annotation);
    text-decoration: none;
    position: relative;
    transition: color 300ms ease-out;
}

.chapter-link::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--color-hover);
    width: 0;
    transition: width 300ms cubic-bezier(0.23, 1, 0.32, 1);
}

.chapter-link.active {
    color: var(--color-title);
}

.chapter-link.active::after {
    width: 100%;
}

.chapter-link:hover {
    color: var(--color-hover);
}

/* ============================================================
   MAIN CONTENT WRAPPER
   ============================================================ */

.content-wrapper {
    position: relative;
    z-index: 1;
    padding-top: var(--nav-height);
}

/* ============================================================
   OPENING VIEWPORT
   ============================================================ */

.opening-viewport {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.opening-container {
    text-align: center;
}

.opening-title {
    font-family: var(--font-geometric);
    font-size: 48px;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--color-title);
    margin-bottom: 16px;
}

.opening-subtitle {
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 300;
    font-style: italic;
    color: var(--color-annotation);
    margin-bottom: 32px;
}

.opening-divider {
    width: 80px;
    height: 1px;
    background-color: var(--color-divider);
    margin: 0 auto 32px;
}

.opening-chevron {
    width: 24px;
    height: 24px;
    margin: 0 auto;
    position: relative;
}

.opening-chevron::before,
.opening-chevron::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 2px;
    background-color: var(--color-annotation);
}

.opening-chevron::before {
    top: 8px;
    left: 0;
    transform: rotate(45deg);
}

.opening-chevron::after {
    top: 8px;
    right: 0;
    transform: rotate(-45deg);
}

@keyframes chevron-pulse {
    0%, 100% {
        opacity: 1;
        transform: translateY(0);
    }
    50% {
        opacity: 0.6;
        transform: translateY(6px);
    }
}

.opening-chevron {
    animation: chevron-pulse 2s ease-in-out infinite;
}

/* ============================================================
   ANNOTATION RAIL
   ============================================================ */

.annotation-rail {
    position: fixed;
    left: calc(50vw - var(--content-width) / 2 - var(--annotation-width) - var(--annotation-offset));
    top: calc(var(--nav-height) + 100px);
    width: var(--annotation-width);
    z-index: 50;
    display: none;
}

@media (min-width: 1200px) {
    .annotation-rail {
        display: block;
    }
}

.chapter-numeral {
    font-family: var(--font-geometric);
    font-size: 120px;
    font-weight: 300;
    color: var(--color-navy);
    opacity: 0.08;
    line-height: 1;
    margin-bottom: 40px;
}

.annotation-item {
    margin-bottom: 40px;
}

.annotation-text {
    font-family: var(--font-geometric);
    font-size: 24px;
    font-weight: 500;
    color: var(--color-diagram);
    line-height: 1.4;
    border-left: 3px solid var(--color-accent);
    padding-left: 24px;
    animation: quote-slide-in 600ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
    opacity: 0;
}

@keyframes quote-slide-in {
    0% {
        opacity: 0;
        transform: translateX(-30px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================================
   CHAPTERS
   ============================================================ */

.chapter {
    position: relative;
    z-index: 2;
    margin-top: 120px;
    margin-bottom: 120px;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 20px;
}

.chapter-title {
    font-family: var(--font-geometric);
    font-size: 42px;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--color-title);
    text-rendering: optimizeLegibility;
    margin-bottom: 40px;
    max-width: var(--content-width);
    animation: title-slide-in 500ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
    opacity: 0;
}

@keyframes title-slide-in {
    0% {
        opacity: 0;
        transform: translateX(40px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.chapter-divider {
    width: 160px;
    height: 1px;
    background-color: var(--color-divider);
    margin-bottom: 40px;
    max-width: var(--content-width);
    animation: divider-fade-in 400ms ease-out forwards;
    opacity: 0;
}

@keyframes divider-fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.article-content {
    max-width: var(--content-width);
    width: 100%;
}

.article-content p {
    margin-bottom: 1.25em;
    color: var(--color-body);
}

.article-content p:first-child {
    animation: paragraph-fade-in 600ms ease-out 100ms forwards;
    opacity: 0;
}

@keyframes paragraph-fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.pull-quote {
    background-color: var(--color-card);
    padding: 40px;
    margin: 40px 0;
    border-left: 3px solid var(--color-accent);
    font-family: var(--font-geometric);
    font-size: 24px;
    font-weight: 500;
    color: var(--color-diagram);
    line-height: 1.5;
    animation: quote-fade-in 600ms ease-out 200ms forwards;
    opacity: 0;
}

@keyframes quote-fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.pull-quote p {
    margin: 0;
}

/* ============================================================
   CHAPTER INTERSTITIALS
   ============================================================ */

.chapter-interstitial {
    background-color: var(--color-interstitial);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    position: relative;
    z-index: 2;
    margin: 120px 0;
}

.diagram {
    width: 300px;
    height: 300px;
    max-width: 90vw;
}

.diagram circle,
.diagram line,
.diagram path {
    stroke: var(--color-diagram);
    fill: none;
    stroke-width: 1.5px;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.diagram circle {
    fill: none;
}

.diagram .ring-outer {
    animation: ring-rotate-outer 2s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    transform-origin: 150px 150px;
}

@keyframes ring-rotate-outer {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.diagram .ring-middle,
.diagram .ring-inner {
    animation: ring-rotate-inner 2s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    transform-origin: 150px 150px;
}

@keyframes ring-rotate-inner {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(-360deg);
    }
}

.diagram .branch-main,
.diagram .branch-center {
    animation: branch-draw-forward 1.8s ease-out forwards;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
}

.diagram .branch-left,
.diagram .branch-right {
    animation: branch-draw-reverse 1.8s ease-out forwards;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
}

@keyframes branch-draw-forward {
    0% {
        stroke-dashoffset: 100;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes branch-draw-reverse {
    0% {
        stroke-dashoffset: -100;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.diagram .node {
    fill: var(--color-diagram);
}

.diagram .flow-circle {
    stroke-width: 2px;
    animation: flow-rotate 3s linear infinite;
    transform-origin: 150px 150px;
}

@keyframes flow-rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.diagram .flow-arrow {
    animation: arrow-draw 1.8s ease-out forwards;
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

@keyframes arrow-draw {
    0% {
        stroke-dashoffset: 200;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.diagram .venn-left,
.diagram .venn-right {
    animation: venn-draw 1.8s ease-out forwards;
    stroke-dasharray: 380;
    stroke-dashoffset: 380;
}

.diagram .venn-left {
    animation-delay: 0s;
}

.diagram .venn-right {
    animation-delay: 200ms;
}

@keyframes venn-draw {
    0% {
        stroke-dashoffset: 380;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.diagram .spoke-ring {
    animation: spoke-ring-draw 1.8s ease-out forwards;
    stroke-dasharray: 754;
    stroke-dashoffset: 754;
}

.diagram .spoke {
    animation: spoke-draw 1.8s ease-out forwards;
    stroke-dasharray: 120;
    stroke-dashoffset: 120;
}

@keyframes spoke-ring-draw {
    0% {
        stroke-dashoffset: 754;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes spoke-draw {
    0% {
        stroke-dashoffset: 120;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

.chapter-interstitial.closing {
    margin-bottom: 0;
}

/* ============================================================
   RESPONSIVE DESIGN
   ============================================================ */

@media (max-width: 1200px) {
    .annotation-rail {
        display: none;
    }
}

@media (max-width: 768px) {
    :root {
        --content-width-percent: 90%;
    }

    .index-bar {
        padding: 0 20px;
    }

    .opening-title {
        font-size: 32px;
    }

    .chapter {
        padding: 0 16px;
    }

    .chapter-title {
        font-size: 28px;
        margin-bottom: 24px;
    }

    .diagram {
        width: 200px;
        height: 200px;
    }

    .pull-quote {
        padding: 24px;
        font-size: 18px;
    }

    .article-content {
        font-size: 17px;
        line-height: 1.6;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ============================================================
   CODE BLOCKS (optional)
   ============================================================ */

code {
    font-family: var(--font-mono);
    font-size: 16px;
    background-color: var(--color-code-bg);
    border: 1px solid var(--color-divider);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--color-body);
}

/* ============================================================
   LINKS AND INTERACTION
   ============================================================ */

a {
    color: var(--color-hover);
    text-decoration: none;
    transition: color 300ms ease-out;
}

a:hover {
    color: var(--color-title);
}

/* ============================================================
   SCROLLBAR STYLING (optional)
   ============================================================ */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background-color: var(--color-void);
}

::-webkit-scrollbar-thumb {
    background-color: var(--color-diagram);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-hover);
}
