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

:root {
    --bg-primary: #f5efe3;
    --bg-deep: #2c1810;
    --accent-orange: #d4763c;
    --accent-teal: #2a7f6f;
    --text-primary: #1a120a;
    --text-secondary: #6b5d50;
    --code-highlight: #b85c38;
    --bokeh-glow: #e8b44d;
    --parchment-warm: #e8dcc8;
    --nav-height: 64px;
    --ease-settle: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Source Serif 4', Georgia, serif;
}

/* === NAVIGATION === */
#nav-band {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-deep);
    z-index: 1000;
    display: flex;
    align-items: center;
    overflow: hidden;
}

.nav-inner {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 2rem;
    position: relative;
    z-index: 2;
}

.nav-title {
    font-family: 'IBM Plex Mono', monospace;
    color: var(--parchment-warm);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    margin-right: 2rem;
}

.nav-chapters {
    display: flex;
    gap: 0.5rem;
}

.nav-ch {
    background: none;
    border: 1px solid var(--text-secondary);
    color: var(--text-secondary);
    font-family: 'Playfair Display', serif;
    font-size: 0.8rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s var(--ease-settle);
}

.nav-ch.active {
    border-color: var(--bokeh-glow);
    color: var(--bokeh-glow);
    background: rgba(232, 180, 77, 0.1);
}

.progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(107, 93, 80, 0.3);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--bokeh-glow);
    transition: width 0.3s var(--ease-settle);
}

.starburst-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.08;
    background-image: radial-gradient(circle, var(--accent-teal) 1px, transparent 1px);
    background-size: 20px 20px;
    z-index: 1;
}

/* === MAIN CONTAINER === */
#chapters-container {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
}

#chapters-container::-webkit-scrollbar {
    display: none;
}

/* === CHAPTERS BASE === */
.chapter {
    min-width: 100vw;
    height: calc(100vh - var(--nav-height));
    scroll-snap-align: start;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === CHAPTER I === */
.chapter-1 {
    background: var(--bg-deep);
}

.chapter-1 .chapter-content {
    padding: clamp(3rem, 6vw, 8rem);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.chapter-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(3.5rem, 8vw, 7rem);
    line-height: 1.0;
    letter-spacing: 0.03em;
    color: var(--parchment-warm);
}

.chapter-subtitle {
    font-family: 'Source Serif 4', serif;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    color: var(--text-secondary);
    margin-top: 1.5rem;
}

.chapter-number {
    position: absolute;
    bottom: 2rem;
    left: clamp(3rem, 6vw, 8rem);
    font-family: 'Playfair Display', serif;
    font-size: 8rem;
    color: rgba(232, 180, 77, 0.06);
    line-height: 1;
}

.book-watermark {
    position: absolute;
    bottom: 5%;
    right: 5%;
    width: clamp(200px, 30vw, 400px);
    z-index: 1;
    animation: pulse-book 4s ease-in-out infinite;
}

@keyframes pulse-book {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.35; }
}

/* === BOKEH === */
.bokeh-field {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.bokeh-circle {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, var(--bokeh-glow), transparent 70%);
    mix-blend-mode: screen;
    animation: bokeh-drift 30s ease-in-out infinite alternate;
}

@keyframes bokeh-drift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(15px, -20px); }
    50% { transform: translate(-10px, 15px); }
    75% { transform: translate(20px, 10px); }
    100% { transform: translate(-15px, -10px); }
}

/* === CHAPTER II === */
.chapter-2 {
    background: linear-gradient(135deg, var(--bg-primary), var(--parchment-warm));
}

.two-col {
    display: flex;
    width: 100%;
    height: 100%;
    padding: clamp(2rem, 4vw, 5rem);
    gap: clamp(1rem, 3vw, 2.5rem);
    align-items: center;
}

.col-primary {
    flex: 0 0 61.8%;
}

.col-secondary {
    flex: 0 0 38.2%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chapter-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 1.1;
    letter-spacing: 0.03em;
    color: var(--bg-deep);
    margin-bottom: 1.5rem;
}

.body-text {
    font-family: 'Source Serif 4', serif;
    font-size: clamp(1rem, 1.15vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: var(--text-primary);
    margin-bottom: 1.2rem;
}

.body-text code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9em;
    color: var(--code-highlight);
}

/* Diagram */
.diagram-curry-howard {
    display: grid;
    grid-template-columns: 1fr 80px 1fr;
    grid-template-rows: auto 30px;
    gap: 0;
    align-items: center;
    width: 100%;
    max-width: 400px;
}

.diagram-col {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.diagram-node {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--bg-deep);
    border-radius: 6px;
    text-align: center;
    background: var(--bg-primary);
    opacity: 0;
    transform: translateX(30px);
    transition: all 0.4s var(--ease-settle);
}

.diagram-node.visible {
    opacity: 1;
    transform: translateX(0);
}

.diagram-arrows svg {
    width: 100%;
    height: 240px;
}

.arrow-line {
    stroke: var(--bg-deep);
    stroke-width: 1.5;
    stroke-dasharray: 80;
    stroke-dashoffset: 80;
    transition: stroke-dashoffset 0.4s var(--ease-settle);
}

.arrow-line.drawn {
    stroke-dashoffset: 0;
}

.arrow-head {
    fill: var(--bg-deep);
    opacity: 0;
    transition: opacity 0.3s 0.3s;
}

.arrow-head.drawn {
    opacity: 1;
}

.diagram-labels {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* === CHAPTER III === */
.chapter-3 {
    background: var(--bg-primary);
}

.diamond-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.08;
    background-image: 
        linear-gradient(45deg, var(--accent-orange) 25%, transparent 25%),
        linear-gradient(-45deg, var(--accent-orange) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--accent-orange) 75%),
        linear-gradient(-45deg, transparent 75%, var(--accent-orange) 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.composition-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    position: relative;
    z-index: 2;
}

.ch3-title {
    color: var(--bg-deep);
}

.composition-diagram {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    padding-top: 80px;
}

.comp-node {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid var(--bg-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.2rem;
    color: var(--bg-deep);
    opacity: 0;
    transition: opacity 0.3s var(--ease-settle);
}

.comp-node.visible {
    opacity: 1;
}

.comp-arrow {
    width: 120px;
    height: 2px;
    opacity: 0;
    transform: scaleX(0);
    transform-origin: left;
    transition: all 0.4s var(--ease-settle);
}

.comp-arrow.visible {
    opacity: 1;
    transform: scaleX(1);
}

.comp-curve {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    opacity: 0;
    transition: opacity 0.6s var(--ease-settle);
}

.comp-curve path {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 0.8s var(--ease-settle);
}

.comp-curve.visible {
    opacity: 1;
}

.comp-curve.visible path {
    stroke-dashoffset: 0;
}

.comp-label {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.1rem;
    color: var(--accent-teal);
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s;
}

.comp-label.visible {
    opacity: 1;
}

/* === CHAPTER IV === */
.chapter-4 {
    background: var(--bg-deep);
}

.monad-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    width: 100%;
    padding: 3rem;
    position: relative;
    z-index: 2;
}

.index-card {
    width: clamp(260px, 22vw, 320px);
    min-height: 240px;
    background: var(--bg-primary);
    border-radius: 4px;
    display: flex;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    position: relative;
    opacity: 0;
    transform: translateY(40px);
    transition: all 0.5s var(--ease-settle);
}

.index-card.visible {
    opacity: 1;
    transform: translateY(0) rotate(var(--rotation));
}

.card-1 { --rotation: -2deg; }
.card-2 { --rotation: 1deg; margin-top: -20px; }
.card-3 { --rotation: -0.5deg; margin-top: 10px; }

.card-margin {
    width: 4px;
    background: var(--code-highlight);
    flex-shrink: 0;
    border-radius: 4px 0 0 4px;
}

.card-body {
    padding: 1.5rem;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.card-body h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    margin-bottom: 0.8rem;
    color: var(--bg-deep);
}

.brace-ornament {
    position: absolute;
    font-family: 'Playfair Display', serif;
    font-size: 12rem;
    color: var(--accent-orange);
    opacity: 0.08;
    z-index: 1;
    line-height: 1;
}

.brace-ornament.top-left {
    top: 5%;
    left: 5%;
}

.brace-ornament.bottom-right {
    bottom: 5%;
    right: 5%;
}

/* === CHAPTER V === */
.chapter-5 {
    background: linear-gradient(135deg, var(--bg-primary), var(--parchment-warm));
}

.quest-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 2.5rem;
    padding: 3rem;
    position: relative;
    z-index: 2;
}

.quest-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4rem);
    line-height: 1.15;
    letter-spacing: 0.03em;
    color: var(--bg-deep);
}

.typewriter-field {
    position: relative;
    width: clamp(300px, 50vw, 600px);
}

#quest-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--bg-deep);
    padding: 0.8rem 0;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.1rem;
    color: var(--text-primary);
    outline: none;
}

#quest-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.cursor-blink {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 1.4rem;
    background: var(--bg-deep);
    animation: blink-cursor 1s step-end infinite;
}

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

.quest-subtitle {
    font-family: 'Source Serif 4', serif;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    #chapters-container {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        scroll-snap-type: y mandatory;
    }

    .chapter {
        min-width: 100vw;
        min-height: calc(100vh - var(--nav-height));
        scroll-snap-align: start;
    }

    .two-col {
        flex-direction: column;
    }

    .col-primary, .col-secondary {
        flex: none;
        width: 100%;
    }

    .monad-content {
        flex-direction: column;
    }

    .nav-title {
        display: none;
    }

    .composition-diagram {
        transform: scale(0.8);
    }
}
