/* ============================================
   haskell.day — The Ascent through Abstractions
   Hexagonal honeycomb + Catppuccin Mocha
   ============================================ */

:root {
    --crust: #11111B;
    --mantle: #181825;
    --base: #1E1E2E;
    --surface1: #45475A;
    --surface2: #313244;
    --text: #CDD6F4;
    --subtext: #BAC2DE;
    --lavender: #CBA6F7;
    --green: #A6E3A1;
    --peach: #FAB387;
    --rosewater: #F5E0DC;
    --amber: #F9E2AF;
    --pink: #F38BA8;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 400;
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--subtext);
    background: var(--crust);
    overflow-x: hidden;
}

/* --- Hexagonal Background Pattern --- */
#hex-bg-pattern {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='100'%3E%3Cpath d='M28 66L0 50V16l28-16 28 16v34L28 66zm0-32l28-16v34L28 66 0 50V16l28 16z' fill='none' stroke='%23CDD6F4' stroke-width='0.5'/%3E%3C/svg%3E");
    background-size: 56px 100px;
}

/* --- Type Signature Nav Bar --- */
#type-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 52px;
    background: rgba(30, 30, 46, 0.95);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px 0 80px;
    z-index: 1000;
    border-bottom: 1px solid var(--surface2);
}

.nav-signature {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 16px;
    color: var(--text);
    font-feature-settings: "liga" 1, "calt" 1;
    white-space: nowrap;
}

.nav-constraints {
    display: flex;
    align-items: center;
    gap: 8px;
}

.constraint {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    transition: color 200ms ease;
    font-feature-settings: "liga" 1, "calt" 1;
}

.constraint:hover {
    color: var(--amber);
}

.nav-arrow {
    font-family: 'Fira Code', monospace;
    font-size: 13px;
    color: var(--surface1);
    font-feature-settings: "liga" 1, "calt" 1;
}

/* --- Lambda Sidebar --- */
#lambda-sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    width: 64px;
    height: calc(100vh - 52px);
    background: var(--mantle);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    z-index: 999;
    transform: translateX(-64px);
    transition: transform 400ms ease-out;
}

#lambda-sidebar.visible {
    transform: translateX(0);
}

.lambda-link {
    font-family: 'Fira Code', monospace;
    font-size: 20px;
    color: var(--pink);
    text-decoration: none;
    transition: transform 200ms ease, text-shadow 200ms ease;
    display: block;
}

.lambda-link.active {
    transform: rotate(15deg);
    text-shadow: 0 0 12px rgba(243, 139, 168, 0.3);
}

/* --- Sections --- */
.hex-section {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 80px 24px 80px 100px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 48px;
}

.section-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--surface1);
    color: var(--amber);
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.section-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.6rem, 3.5vw, 3rem);
    letter-spacing: -0.02em;
    color: var(--text);
}

.display-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4rem);
    color: var(--text);
    letter-spacing: -0.02em;
    min-height: 1.2em;
}

.subtitle {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 400;
    font-size: 1.2rem;
    color: var(--subtext);
    opacity: 0;
    transition: opacity 600ms ease;
    margin-top: 8px;
    margin-bottom: 40px;
}

.subtitle.visible {
    opacity: 1;
}

/* --- Hexagonal Cells --- */
.hex-cell {
    width: 200px;
    height: 231px;
    background: var(--base);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
    text-align: center;
}

.hex-cell:hover {
    transform: scale(1.04);
}

.hex-code {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1.5;
    font-feature-settings: "liga" 1, "calt" 1;
    word-break: break-all;
}

.code-literal { color: var(--green); }
.code-op { color: var(--text); }
.code-type { color: var(--lavender); }
.code-fn { color: var(--green); }
.code-keyword { color: var(--lavender); }

/* Hero hex */
.values-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
}

.hero-hex {
    margin-top: 30px;
}

.hero-cell {
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 400ms ease, transform 600ms ease-in-out;
}

.hero-cell.visible {
    opacity: 1;
    transform: scale(1);
}

.hero-cell.pulse {
    animation: hex-pulse 600ms ease-in-out;
}

@keyframes hex-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* --- Honeycomb Cluster --- */
.honeycomb-cluster {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.hex-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.hex-row-offset {
    margin-left: 103px;
}

.honeycomb-cluster .hex-cell {
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 300ms ease, transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.honeycomb-cluster .hex-cell.visible {
    opacity: 1;
    transform: scale(1);
}

/* Inference arrows */
.inference-arrows {
    width: 80%;
    max-width: 800px;
    height: 40px;
    margin: 30px auto;
    display: block;
    opacity: 0.4;
}

/* --- Type Class Blocks --- */
.typeclass-block {
    margin-bottom: 80px;
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 500ms ease, transform 500ms ease;
}

.typeclass-block.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Isometric Cards */
.iso-card {
    max-width: 500px;
    margin: 0 auto 30px;
    perspective: 800px;
}

.iso-card-inner {
    background: var(--base);
    border-left: 3px solid var(--pink);
    padding: 30px;
    transform: rotateX(8deg) rotateZ(-2deg);
    transform-style: preserve-3d;
    box-shadow: 8px 8px 20px var(--crust);
    border-right: 2px solid var(--surface1);
    border-bottom: 2px solid var(--surface1);
}

.iso-card-functor .iso-card-inner {
    border-left-color: var(--peach);
}

.iso-card-applicative .iso-card-inner {
    border-left-color: var(--amber);
}

.iso-card-monad .iso-card-inner {
    border-left-color: var(--pink);
}

.tc-name {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text);
    margin-bottom: 12px;
}

.tc-def {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    line-height: 1.6;
    font-feature-settings: "liga" 1, "calt" 1;
    display: block;
}

.tc-law-diagram {
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
}

.tc-law {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--subtext);
    margin-bottom: 8px;
    font-feature-settings: "liga" 1, "calt" 1;
}

/* --- Lambda Tree --- */
.lambda-tree-container {
    display: flex;
    justify-content: center;
    padding: 40px 0;
}

#lambda-tree {
    width: 100%;
    max-width: 400px;
    height: auto;
}

.tree-branch {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 300ms ease;
}

.tree-branch.drawn {
    stroke-dashoffset: 0;
}

/* --- Pipeline Section --- */
.pipeline-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 60px 0;
}

.pipeline-hex {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.pipe-cell {
    width: 120px;
    height: 139px;
}

.pipe-label {
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--subtext);
}

.pipeline-arrow {
    font-family: 'Fira Code', monospace;
    font-size: 1.2rem;
    color: var(--surface1);
    font-feature-settings: "liga" 1, "calt" 1;
}

.pipe-cell[data-category="functor"] {
    background: var(--base);
    box-shadow: inset 0 0 0 3px var(--peach);
}

.pipe-cell[data-category="applicative"] {
    background: var(--base);
    box-shadow: inset 0 0 0 3px var(--amber);
}

.pipe-cell[data-category="monad"] {
    background: var(--base);
    box-shadow: inset 0 0 0 3px var(--pink);
}

#pipeline-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px rgba(166, 227, 161, 0.5);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    transition: background 400ms ease;
}

/* --- IO Final Section --- */
.io-final-hex {
    display: flex;
    justify-content: center;
    padding: 60px 0;
}

.final-cell {
    width: 280px;
    height: 323px;
    transition: border-color 800ms ease;
}

#final-hex {
    position: relative;
}

.ghci-session {
    text-align: left;
}

.ghci-line {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    display: block;
    margin-bottom: 6px;
    font-feature-settings: "liga" 1, "calt" 1;
}

/* Color cycling animation for final hex */
@keyframes color-cycle {
    0%   { box-shadow: inset 0 0 0 3px var(--lavender); }
    20%  { box-shadow: inset 0 0 0 3px var(--green); }
    40%  { box-shadow: inset 0 0 0 3px var(--peach); }
    60%  { box-shadow: inset 0 0 0 3px var(--amber); }
    80%  { box-shadow: inset 0 0 0 3px var(--pink); }
    100% { box-shadow: inset 0 0 0 3px var(--lavender); }
}

.final-cell.cycling {
    animation: color-cycle 4s infinite ease;
}

/* --- Footer REPL --- */
#repl-footer {
    padding: 40px 24px 40px 100px;
    background: var(--mantle);
    border-top: 1px solid var(--surface2);
}

.repl-prompt {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.repl-prefix {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--green);
    font-feature-settings: "liga" 1, "calt" 1;
}

.repl-input {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--text);
    font-feature-settings: "liga" 1, "calt" 1;
}

.repl-cursor {
    display: inline-block;
    width: 8px;
    height: 18px;
    background: var(--text);
    animation: blink 1s step-end infinite;
}

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

.repl-output {
    padding-left: 0;
}

.repl-output code {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--amber);
    font-feature-settings: "liga" 1, "calt" 1;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    .hero-cell {
        opacity: 1;
        transform: none;
    }

    .honeycomb-cluster .hex-cell {
        opacity: 1;
        transform: none;
    }

    .typeclass-block {
        opacity: 1;
        transform: none;
    }

    .tree-branch {
        stroke-dashoffset: 0;
    }

    .repl-cursor {
        animation: none;
        opacity: 1;
    }

    .final-cell.cycling {
        animation: none;
    }

    #lambda-sidebar {
        transform: translateX(0);
    }

    .subtitle {
        opacity: 1;
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #lambda-sidebar {
        display: none;
    }

    .hex-section {
        padding: 80px 16px 80px 16px;
    }

    #type-nav {
        padding: 0 16px;
    }

    .nav-constraints {
        display: none;
    }

    .hex-cell {
        width: 160px;
        height: 185px;
        padding: 20px;
    }

    .hex-code {
        font-size: 0.7rem;
    }

    .hex-row-offset {
        margin-left: 83px;
    }

    .pipe-cell {
        width: 90px;
        height: 104px;
    }

    .pipeline-container {
        gap: 8px;
    }

    .pipeline-arrow {
        font-size: 0.9rem;
    }

    .final-cell {
        width: 220px;
        height: 254px;
    }

    #repl-footer {
        padding: 30px 16px;
    }

    .iso-card-inner {
        transform: none;
    }
}
