/* ============================================
   haskeller.net — styles.css
   Lambda calculus proof rendered as architecture
   ============================================ */

/* --- CSS Custom Properties (Palette) --- */
:root {
    --deep-void: #1B1733;
    --soft-ink: #2D2A3E;
    --lambda-purple: #7B6BA0;
    --parchment: #FAF8F5;
    --pale-lilac: #F0ECF5;
    --near-white: #F7F5FA;
    --type-gold: #C9A84C;
    --reduction-red: #B5485A;
    --proof-green: #5A8A6C;
}

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

html {
    scroll-behavior: smooth;
    font-size: 100%;
}

body {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: var(--soft-ink);
    background-color: var(--parchment);
    overflow-x: hidden;
    position: relative;
}

/* --- Noise Overlay (paper grain) --- */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: multiply;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* --- Lambda Spine --- */
.lambda-spine {
    position: fixed;
    left: calc(50% - 19em + 8%);
    top: 0;
    width: 1px;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
}

.spine-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    background-color: var(--lambda-purple);
    opacity: 0.15;
}

.spine-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 0%;
    background-color: var(--lambda-purple);
    opacity: 0.5;
    transition: height 0.1s linear;
}

@media (max-width: 1100px) {
    .lambda-spine {
        left: 1.5rem;
    }
}

@media (max-width: 768px) {
    .lambda-spine {
        display: none;
    }
}

/* --- Sidebar Navigation --- */
.sidebar-nav {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    z-index: 100;
    padding: 1rem 0;
}

.nav-dot {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--lambda-purple);
    opacity: 0.4;
    transition: opacity 0.3s ease;
    position: relative;
    width: 3rem;
    justify-content: center;
}

.nav-dot.active {
    opacity: 1;
}

.nav-dot:hover {
    opacity: 1;
}

.dot-char {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 500;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.dot-label {
    position: absolute;
    left: 3rem;
    white-space: nowrap;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    background: var(--parchment);
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--pale-lilac);
    border-radius: 3px;
    opacity: 0;
    transform: translateX(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    color: var(--soft-ink);
}

.nav-dot:hover .dot-label {
    opacity: 1;
    transform: translateX(0);
}

@media (max-width: 768px) {
    .sidebar-nav {
        display: none;
    }
}

/* --- Hero Section --- */
.hero-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2rem;
    overflow: hidden;
}

.lambda-watermark {
    position: absolute;
    font-family: 'Crimson Pro', serif;
    font-size: 20vw;
    color: var(--lambda-purple);
    opacity: 0;
    user-select: none;
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.8s ease;
    will-change: transform;
}

.lambda-watermark.visible {
    opacity: 0.08;
}

.hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
}

.hero-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    color: var(--deep-void);
    letter-spacing: 0.05em;
    min-height: 2em;
    margin-bottom: 1rem;
}

.hero-title .cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--lambda-purple);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink-cursor 0.8s steps(1) infinite;
}

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

.hero-subtitle {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: clamp(1.4rem, 2.8vw, 2.2rem);
    color: var(--soft-ink);
    opacity: 0;
    transition: opacity 0.6s ease;
}

.hero-subtitle.visible {
    opacity: 1;
}

/* --- Lambda Reduction Visualizer --- */
.reduction-visualizer {
    position: relative;
    z-index: 1;
    margin-top: 3rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.6s ease 0.3s;
}

.reduction-visualizer.visible {
    opacity: 1;
}

.reduction-expression {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(1rem, 1.8vw, 1.4rem);
    color: var(--soft-ink);
    min-height: 2.5em;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
    flex-wrap: wrap;
}

.reduction-expression .redex {
    color: var(--type-gold);
    transition: color 0.4s ease, opacity 0.4s ease;
}

.reduction-expression .result {
    color: var(--proof-green);
    transition: color 0.4s ease, opacity 0.4s ease;
}

.reduction-expression .token {
    display: inline-block;
    transition: transform 0.5s ease, opacity 0.5s ease, color 0.4s ease;
}

.reduction-step-btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--lambda-purple);
    background: transparent;
    border: 1px solid var(--lambda-purple);
    padding: 0.4rem 1rem;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.2s ease, color 0.2s ease;
    margin-top: 0.5rem;
}

.reduction-step-btn:hover {
    background: var(--lambda-purple);
    color: var(--parchment);
}

/* --- Type Signature Dividers --- */
.type-divider {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--lambda-purple);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.type-divider.visible {
    opacity: 1;
    transform: translateY(0);
}

.td-comment {
    color: var(--soft-ink);
    opacity: 0.45;
}

.td-double-colon {
    color: var(--lambda-purple);
}

.td-type {
    color: var(--type-gold);
}

.td-arrow {
    color: var(--lambda-purple);
}

.td-keyword {
    color: var(--soft-ink);
}

/* --- Content Sections --- */
.content-section {
    position: relative;
    max-width: 72rem;
    margin: 0 auto;
    padding: 4rem 2rem 4rem calc(3rem + 2rem);
    display: grid;
    grid-template-columns: minmax(0, 38em) 1fr;
    gap: 3rem;
    align-items: start;
}

@media (min-width: 1100px) {
    .content-section {
        padding-left: calc(8% + 3rem);
    }
}

.section-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: 15vw;
    color: var(--lambda-purple);
    opacity: 0.035;
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
    z-index: 0;
}

.main-column {
    position: relative;
    z-index: 1;
}

.section-heading {
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--deep-void);
    margin-bottom: 1.5rem;
}

.body-text {
    margin-bottom: 1.2rem;
}

.body-text em {
    font-style: italic;
    color: var(--deep-void);
}

/* --- Margin Notes --- */
.margin-column {
    position: relative;
    z-index: 1;
}

.margin-note {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--soft-ink);
    opacity: 0.85;
    padding: 0.8rem 0;
    margin-bottom: 1.5rem;
}

@media (max-width: 1100px) {
    .content-section {
        grid-template-columns: 1fr;
        padding-left: 2rem;
        padding-right: 2rem;
    }

    .margin-column {
        order: -1;
        display: flex;
        flex-direction: column;
    }

    .margin-note {
        border-left: 2px solid var(--lambda-purple);
        padding-left: 1rem;
        margin-left: 0;
        margin-bottom: 1rem;
    }

    .section-watermark {
        font-size: 25vw;
    }
}

/* --- Inline Code --- */
.inline-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
    line-height: 1.55;
    color: var(--lambda-purple);
    background: var(--pale-lilac);
    padding: 0.15em 0.4em;
    border-radius: 3px;
}

/* --- Code Blocks --- */
.code-block {
    background: var(--near-white);
    border-left: 3px solid var(--lambda-purple);
    border-radius: 0 4px 4px 0;
    margin: 1.5rem 0;
    overflow-x: auto;
}

.code-header {
    padding: 0.5rem 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--lambda-purple);
    opacity: 0.6;
    border-bottom: 1px solid var(--pale-lilac);
}

.code-content {
    padding: 1rem 1.2rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88em;
    line-height: 1.55;
    color: var(--soft-ink);
    overflow-x: auto;
}

.code-content code {
    font-family: inherit;
}

/* Syntax highlighting */
.hl-keyword {
    color: var(--lambda-purple);
    font-weight: 500;
}

.hl-type {
    color: var(--type-gold);
}

.hl-string {
    color: var(--proof-green);
}

.hl-comment {
    color: var(--soft-ink);
    opacity: 0.45;
}

/* --- Category Theory Diagrams --- */
.category-diagram {
    margin: 2.5rem auto;
    max-width: 28rem;
    text-align: center;
    grid-column: 1 / -1;
}

.cd-svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.cd-node {
    fill: var(--lambda-purple);
    opacity: 0;
    transform-origin: center;
    transform: scale(0);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cd-node.animated {
    opacity: 1;
    transform: scale(1);
}

.cd-arrow {
    fill: none;
    stroke: var(--soft-ink);
    stroke-width: 1.5;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 0.6s ease;
}

.cd-arrow.animated {
    stroke-dashoffset: 0;
}

.cd-arrow-nat {
    stroke: var(--type-gold);
    stroke-dasharray: 4 3;
}

.cd-arrow-nat.animated {
    stroke-dasharray: 4 3;
    stroke-dashoffset: 0;
}

.cd-arrowhead {
    fill: var(--soft-ink);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cd-arrowhead.animated {
    opacity: 1;
}

.cd-arrowhead-nat {
    fill: var(--type-gold);
}

.cd-label {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: 14px;
    fill: var(--soft-ink);
    text-anchor: middle;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.cd-label.animated {
    opacity: 1;
}

.cd-label-cat {
    font-family: 'JetBrains Mono', monospace;
    font-style: normal;
    font-size: 11px;
    fill: var(--lambda-purple);
}

.cd-label-nat {
    fill: var(--type-gold);
    font-size: 16px;
}

.cd-caption {
    font-family: 'Source Serif 4', Georgia, serif;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--soft-ink);
    opacity: 0.6;
    margin-top: 0.8rem;
}

/* --- Curry-Howard Corridor --- */
.curry-howard-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    background: linear-gradient(180deg, var(--parchment) 0%, var(--pale-lilac) 50%, var(--parchment) 100%);
    position: relative;
}

.ch-split {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    max-width: 64rem;
}

.ch-left, .ch-right {
    flex: 1;
    padding: 2rem;
    min-width: 0;
}

.ch-heading {
    font-family: 'Crimson Pro', serif;
    font-weight: 300;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    color: var(--deep-void);
    margin-bottom: 1.5rem;
    text-align: center;
}

.ch-panel {
    position: relative;
    min-height: 10rem;
}

.ch-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    pointer-events: none;
}

.ch-item.active {
    position: relative;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.ch-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88em;
    line-height: 1.6;
    background: var(--near-white);
    padding: 1.2rem 1.5rem;
    border-radius: 4px;
    border-left: 3px solid var(--lambda-purple);
    color: var(--soft-ink);
    overflow-x: auto;
}

.ch-code.ch-proof {
    border-left-color: var(--type-gold);
}

.ch-arrows {
    width: 5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ch-arrow-svg {
    width: 80px;
    height: 80px;
    overflow: visible;
}

.ch-arrow-path {
    fill: none;
    stroke: var(--lambda-purple);
    stroke-width: 1.5;
}

.ch-arrow-head {
    fill: var(--lambda-purple);
}

.ch-iso-label {
    font-family: 'Crimson Pro', serif;
    font-size: 20px;
    fill: var(--type-gold);
    text-anchor: middle;
}

.ch-caption {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: clamp(0.9rem, 1.2vw, 1.1rem);
    color: var(--soft-ink);
    text-align: center;
    margin-top: 2rem;
    opacity: 0.7;
}

.ch-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.ch-nav-btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--lambda-purple);
    background: transparent;
    border: 1px solid var(--lambda-purple);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.ch-nav-btn:hover {
    background: var(--lambda-purple);
    color: var(--parchment);
}

.ch-nav-indicator {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--soft-ink);
    opacity: 0.6;
}

@media (max-width: 768px) {
    .ch-split {
        flex-direction: column;
    }

    .ch-arrows {
        transform: rotate(90deg);
        width: 80px;
        height: 60px;
    }

    .ch-left, .ch-right {
        padding: 1rem;
    }
}

/* --- Closing Section --- */
.closing-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 4rem 2rem;
    position: relative;
}

.hm-tree-container {
    width: 100%;
    max-width: 40rem;
    flex-grow: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 2rem;
}

.hm-tree-svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.hm-branch {
    fill: none;
    stroke: var(--lambda-purple);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 0.8s ease;
}

.hm-branch.animated {
    stroke-dashoffset: 0;
}

.hm-trunk {
    stroke-width: 3;
}

.hm-branch:nth-child(even) {
    stroke: var(--proof-green);
}

.hm-node {
    fill: var(--lambda-purple);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.hm-node.animated {
    opacity: 1;
}

.hm-leaf {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    fill: var(--lambda-purple);
    text-anchor: middle;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.hm-leaf.animated {
    opacity: 1;
}

.hm-junction-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    fill: var(--soft-ink);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.hm-junction-label.animated {
    opacity: 0.6;
}

/* --- Closing Quote --- */
.closing-quote {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--type-gold);
    text-align: center;
    margin-bottom: 3rem;
    line-height: 1.4;
}

.quote-attribution {
    display: block;
    font-size: 0.6em;
    font-style: normal;
    color: var(--soft-ink);
    opacity: 0.5;
    margin-top: 0.5rem;
}

/* --- Footer --- */
.site-footer {
    width: 100%;
    padding: 2rem 0;
}

.footer-content {
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--soft-ink);
    opacity: 0.5;
}

.footer-separator {
    margin: 0 0.8rem;
}

/* --- Reveal Animations --- */
.reveal-up {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.reveal-up.visible {
    opacity: 1;
    transform: translateY(0);
}

.reveal-right {
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.reveal-right.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Stagger delays for body text */
.content-section .body-text:nth-child(2) { transition-delay: 0ms; }
.content-section .body-text:nth-child(3) { transition-delay: 80ms; }
.content-section .body-text:nth-child(4) { transition-delay: 160ms; }
.content-section .body-text:nth-child(5) { transition-delay: 240ms; }
.content-section .code-block { transition-delay: 120ms; }

/* Margin notes stagger */
.margin-note:nth-child(1) { transition-delay: 200ms; }
.margin-note:nth-child(2) { transition-delay: 350ms; }

/* --- Selection styling --- */
::selection {
    background: var(--pale-lilac);
    color: var(--deep-void);
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--lambda-purple);
    opacity: 0.3;
    border-radius: 3px;
}

/* --- Link styling --- */
a {
    color: var(--lambda-purple);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--type-gold);
}
