/* ===================================================
   haskell.day — Styles
   Forest-green scholarly design, code-as-imagery
   =================================================== */

/* --- CSS Custom Properties --- */
:root {
    --deep-forest: #1B3A2D;
    --body-text: #2C3E2D;
    --terminal-green: #2D6A4F;
    --code-bg: #0D1F17;
    --page-bg: #F4F1EB;
    --sidenote: #5D7A64;
    --code-text: #C8E6C9;
    --highlight: #A8B545;
    --rule-lines: #B5C7B0;
    --error-amber: #C17817;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.05rem);
    line-height: 1.75;
    color: var(--body-text);
    background-color: var(--page-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Lambda Watermark --- */
.lambda-watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(12deg);
    font-size: 40vh;
    font-family: 'Space Grotesk', sans-serif;
    color: var(--deep-forest);
    opacity: 0.03;
    pointer-events: none;
    z-index: 0;
    user-select: none;
    animation: lambda-drift 120s ease-in-out infinite;
}

@keyframes lambda-drift {
    0%, 100% {
        transform: translate(-50%, -50%) rotate(12deg) translateY(0);
    }
    50% {
        transform: translate(-50%, -50%) rotate(12deg) translateY(20px);
    }
}

/* --- Scroll Progress Indicator --- */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 2px;
    height: 100vh;
    z-index: 100;
    pointer-events: none;
}

.scroll-progress-bar {
    width: 100%;
    height: 0%;
    background-color: var(--terminal-green);
    transition: height 0.1s linear;
}

.scroll-progress-cursor {
    width: 2px;
    height: 6px;
    background-color: var(--terminal-green);
    position: absolute;
    left: 0;
    bottom: auto;
    animation: cursor-blink 1s step-end infinite;
}

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

/* --- Site Header --- */
.site-header {
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 50;
}

.site-id {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    color: var(--terminal-green);
    text-decoration: none;
    display: block;
    margin-bottom: 0.25rem;
}

.site-id:hover {
    color: var(--highlight);
}

.module-nav {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: var(--sidenote);
    line-height: 1.5;
    max-width: 280px;
}

.module-keyword {
    color: var(--terminal-green);
}

.module-name {
    color: var(--highlight);
}

.module-export {
    color: var(--sidenote);
    text-decoration: none;
    transition: color 0.3s ease;
}

.module-export:hover {
    color: var(--highlight);
}

/* --- Main Content --- */
.content {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 2rem;
    position: relative;
    z-index: 1;
}

/* --- Opening / Epigraph --- */
.opening {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.hero-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(1.8rem, 4vw, 3rem);
    font-feature-settings: "liga" 1, "calt" 1;
    line-height: 1.4;
    margin-bottom: 4rem;
    color: var(--code-text);
    text-shadow: 0 0 20px rgba(200, 230, 201, 0.15);
}

.scroll-chevron {
    opacity: 0;
    animation: chevron-fade 0.8s ease 3s forwards;
}

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

.scroll-chevron svg {
    animation: chevron-bounce 3s ease-in-out infinite;
}

@keyframes chevron-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(6px);
    }
}

/* --- Section Dividers --- */
.section-divider {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--terminal-green);
    opacity: 0.3;
    text-align: center;
    padding: 3rem 0;
    user-select: none;
}

/* --- Sections --- */
.section {
    padding: 3rem 0 6rem 0;
    position: relative;
}

.section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    letter-spacing: 0.01em;
    color: var(--deep-forest);
    margin-bottom: 0.75rem;
}

.type-summary {
    margin-bottom: 2rem;
}

.type-summary code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.8rem, 1.4vw, 0.9rem);
    color: var(--sidenote);
    background: transparent;
}

/* --- Body Text --- */
.body-text {
    position: relative;
    margin-bottom: 2.5rem;
}

.body-text p {
    margin-bottom: 1.5rem;
}

.body-text p:last-child {
    margin-bottom: 0;
}

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

.body-text code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88em;
    color: var(--terminal-green);
    background-color: rgba(45, 106, 79, 0.08);
    padding: 0.1em 0.35em;
    border-radius: 2px;
}

/* --- Sidenotes --- */
.sidenote {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--sidenote);
    line-height: 1.55;
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
    padding-left: 1rem;
    border-left: 2px solid var(--rule-lines);
}

/* Wide screens: margin annotation */
@media (min-width: 1200px) {
    .body-text {
        position: relative;
    }

    .sidenote {
        position: absolute;
        right: -260px;
        width: 200px;
        margin-top: 0;
        margin-bottom: 0;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid var(--rule-lines);
        padding-top: 0.5rem;
    }
}

/* --- Hero Code Blocks (large display) --- */
.hero-code-block {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(1.4rem, 3vw, 2.4rem);
    font-feature-settings: "liga" 1, "calt" 1;
    line-height: 1.5;
    background-color: var(--code-bg);
    padding: 2rem 2.5rem;
    border-radius: 2px;
    border-left: 3px solid var(--terminal-green);
    margin-bottom: 2.5rem;
    box-shadow: 0 2px 12px rgba(13, 31, 23, 0.25);
    color: var(--code-text);
    text-shadow: 0 0 15px rgba(200, 230, 201, 0.1);
    overflow-x: auto;
}

/* --- Code Blocks --- */
.code-block {
    position: relative;
    background-color: var(--code-bg);
    border-radius: 2px;
    border-left: 3px solid var(--terminal-green);
    padding: 1.5rem 2rem;
    margin-bottom: 2.5rem;
    box-shadow: 0 2px 12px rgba(13, 31, 23, 0.25);
    overflow-x: auto;
}

.code-label {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.7rem;
    color: var(--sidenote);
    user-select: none;
}

.code-block pre {
    margin: 0;
}

.code-block code {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(0.85rem, 1.5vw, 0.95rem);
    font-feature-settings: "liga" 1, "calt" 1;
    line-height: 1.5;
    color: var(--code-text);
}

/* --- Syntax Highlighting --- */
.hl-keyword {
    color: var(--terminal-green);
}

.hl-type,
.hl-constructor {
    color: var(--highlight);
}

.hl-string {
    color: var(--code-text);
}

.hl-comment {
    color: var(--sidenote);
    font-style: italic;
}

.hl-operator {
    color: var(--rule-lines);
}

.hl-function {
    color: var(--terminal-green);
}

.hl-variable {
    color: var(--code-text);
}

.hl-literal {
    color: var(--error-amber);
}

/* --- Category Theory Diagrams --- */
.diagram-container {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 2rem 0;
}

.category-diagram {
    max-width: 100%;
    height: auto;
}

.diagram-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.95rem;
    fill: var(--deep-forest);
    font-weight: 600;
}

.diagram-edge-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    fill: var(--terminal-green);
    text-anchor: middle;
}

.diagram-arrow {
    stroke: var(--terminal-green);
    stroke-width: 1.5;
    fill: none;
}

.diagram-arrowhead {
    fill: var(--terminal-green);
}

.diagram-caption {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.8rem;
    color: var(--sidenote);
    margin-top: 1rem;
}

.diagram-caption code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    color: var(--terminal-green);
    background: transparent;
}

/* --- SVG Diagram Draw Animation --- */
.diagram-arrow {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1.5s ease-in-out;
}

.diagram-container.revealed .diagram-arrow {
    stroke-dashoffset: 0;
}

/* --- Closing Section --- */
.closing {
    padding: 6rem 0 8rem 0;
    text-align: center;
}

.closing-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(1rem, 2vw, 1.4rem);
    font-feature-settings: "liga" 1, "calt" 1;
    color: var(--code-text);
    line-height: 1.6;
    background-color: var(--code-bg);
    display: inline-block;
    padding: 2rem 3rem;
    border-radius: 2px;
    border-left: 3px solid var(--terminal-green);
    box-shadow: 0 2px 12px rgba(13, 31, 23, 0.25);
    text-align: left;
    margin-bottom: 1.5rem;
}

.closing-attribution {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--sidenote);
    font-style: italic;
}

/* --- Fade Reveal Animation --- */
.fade-reveal {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.fade-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Code blocks delay */
.code-block.fade-reveal {
    transition-delay: 0.2s;
}

/* Sidenotes delay */
.sidenote.fade-reveal {
    transition-delay: 0.4s;
}

/* --- Selection Style --- */
::selection {
    background-color: var(--highlight);
    color: var(--code-bg);
}

/* --- Responsive: Tablet --- */
@media (max-width: 768px) {
    .site-header {
        position: relative;
        top: 0;
        left: 0;
        padding: 1.5rem 2rem;
    }

    .module-nav {
        max-width: 100%;
    }

    .content {
        padding: 0 1.5rem;
    }

    .sidenote {
        position: relative;
        right: auto;
        width: 100%;
        margin-top: 0.5rem;
        margin-bottom: 1.5rem;
        padding-left: 1rem;
        border-left: 2px solid var(--rule-lines);
        border-top: none;
        padding-top: 0;
    }
}

/* --- Responsive: Mobile --- */
@media (max-width: 480px) {
    .content {
        padding: 0 1rem;
    }

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

    .hero-code-block {
        font-size: clamp(1rem, 5vw, 1.4rem);
        padding: 1.5rem;
    }

    .code-block {
        padding: 1rem 1.25rem;
    }

    .hero-code {
        font-size: clamp(1.2rem, 6vw, 2rem);
    }

    .site-header {
        padding: 1rem;
    }

    .module-nav {
        font-size: 10px;
    }

    .closing-code {
        padding: 1.5rem 2rem;
        font-size: clamp(0.85rem, 3vw, 1.1rem);
    }
}

/* --- Scrollbar Styling --- */
.code-block pre::-webkit-scrollbar,
.hero-code-block::-webkit-scrollbar {
    height: 4px;
}

.code-block pre::-webkit-scrollbar-track,
.hero-code-block::-webkit-scrollbar-track {
    background: var(--code-bg);
}

.code-block pre::-webkit-scrollbar-thumb,
.hero-code-block::-webkit-scrollbar-thumb {
    background: var(--terminal-green);
    border-radius: 2px;
}

/* --- Link Styles --- */
a {
    color: var(--terminal-green);
    text-decoration: none;
    transition: color 0.3s ease;
}

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