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

:root {
    --bg: #0a0e27;
    --text: #f0f1f5;
    --cyan: #00d9ff;
    --magenta: #ff006e;
    --lime: #00ff88;
    --gray: #4a5568;
    --orange: #ffa500;
    --font-headline: 'Space Mono', monospace;
    --font-body: 'Lato', sans-serif;
    --font-data: 'IBM Plex Mono', monospace;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    overflow-x: hidden;
    line-height: 1.6;
}

/* ===== Canvas Layers ===== */
#noiseCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    opacity: 0.18;
    pointer-events: none;
}

#particleCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    pointer-events: none;
}

#gridOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
    background-image:
        linear-gradient(to right, rgba(74, 85, 104, 0.12) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(74, 85, 104, 0.12) 1px, transparent 1px);
    background-size: 60px 60px;
}

#gridOverlay.visible {
    opacity: 1;
}

/* ===== Hero Section ===== */
#hero {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.hero-content {
    text-align: center;
    max-width: 800px;
}

.kinetic-title {
    font-family: var(--font-headline);
    font-size: clamp(6rem, 15vw, 14rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1;
    margin-bottom: 1.5rem;
    position: relative;
}

.kinetic-title .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(60px) rotateX(30deg);
    animation: charReveal 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: calc(var(--i) * 0.15s + 0.3s);
    background: linear-gradient(135deg, var(--cyan), var(--magenta));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes charReveal {
    to {
        opacity: 1;
        transform: translateY(0) rotateX(0deg);
    }
}

.hero-subtitle {
    font-family: var(--font-body);
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    font-weight: 300;
    color: var(--text);
    opacity: 0;
    animation: fadeUp 1s ease forwards 0.8s;
    margin-bottom: 3rem;
}

.accent-data {
    font-family: var(--font-data);
    color: var(--cyan);
    font-size: 0.85em;
}

.hero-curve {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    opacity: 0;
    animation: fadeUp 1.2s ease forwards 1.2s;
}

.hero-curve svg {
    width: 100%;
    height: auto;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    animation: fadeUp 1s ease forwards 1.8s;
}

.scroll-line {
    width: 1px;
    height: 40px;
    background: var(--cyan);
    animation: scrollPulse 2s ease-in-out infinite;
}

@keyframes scrollPulse {
    0%, 100% { transform: scaleY(0.4); opacity: 0.3; }
    50% { transform: scaleY(1); opacity: 1; }
}

/* ===== Sections ===== */
.section {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6rem 2rem;
}

.section-inner {
    max-width: 900px;
    width: 100%;
    opacity: 0;
    transform: translateY(50px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.section-inner.visible {
    opacity: 1;
    transform: translateY(0);
}

.section-label {
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 1rem;
    color: var(--cyan);
}

.section-title {
    font-family: var(--font-headline);
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 700;
    margin-bottom: 1.5rem;
    line-height: 1.1;
    color: var(--text);
}

.section-body {
    font-size: clamp(1rem, 1.5vw, 1.2rem);
    font-weight: 300;
    color: rgba(240, 241, 245, 0.75);
    max-width: 700px;
    margin-bottom: 3rem;
    line-height: 1.8;
}

/* ===== Normal Distribution Viz ===== */
.distribution-viz {
    width: 100%;
    margin-bottom: 2rem;
    border: 1px solid rgba(74, 85, 104, 0.3);
    border-radius: 4px;
    padding: 1rem;
    background: rgba(10, 14, 39, 0.6);
}

.distribution-viz svg {
    width: 100%;
    height: auto;
}

.svg-label {
    font-family: var(--font-data);
    font-size: 12px;
}

.stat-row {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.stat-value {
    font-family: var(--font-headline);
    font-size: 1.5rem;
    color: var(--text);
}

/* ===== Bayesian Section ===== */
.bayes-formula {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-family: var(--font-headline);
    font-size: clamp(1.2rem, 3vw, 2rem);
    margin-bottom: 3rem;
    flex-wrap: wrap;
}

.formula-part {
    color: var(--cyan);
}

.formula-equals {
    color: var(--gray);
}

.formula-fraction {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.formula-num {
    color: var(--lime);
    padding-bottom: 0.3rem;
    border-bottom: 2px solid var(--gray);
}

.formula-denom {
    color: var(--orange);
    padding-top: 0.3rem;
}

.dendrogram-container {
    width: 100%;
    border: 1px solid rgba(74, 85, 104, 0.3);
    border-radius: 4px;
    background: rgba(10, 14, 39, 0.6);
    overflow: hidden;
}

#dendrogramCanvas {
    width: 100%;
    height: auto;
    display: block;
}

/* ===== Entropy Section ===== */
.entropy-bars {
    display: flex;
    gap: 2rem;
    align-items: flex-end;
    justify-content: center;
    height: 250px;
    margin-bottom: 2rem;
    padding: 1rem;
    border: 1px solid rgba(74, 85, 104, 0.3);
    border-radius: 4px;
    background: rgba(10, 14, 39, 0.6);
}

.entropy-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    max-width: 100px;
}

.entropy-bar-group::after {
    content: attr(data-label);
    font-family: var(--font-data);
    font-size: 0.7rem;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.entropy-bar {
    width: 100%;
    height: 0;
    background: var(--color);
    border-radius: 2px 2px 0 0;
    transition: height 1.5s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.entropy-bar-group.animate .entropy-bar {
    height: calc(var(--entropy) * 180px);
}

.entropy-value {
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.8s ease 0.6s;
}

.entropy-bar-group.animate .entropy-value {
    opacity: 1;
}

.entropy-formula {
    text-align: center;
    font-size: 1.1rem;
    padding: 1.5rem;
    border: 1px solid rgba(74, 85, 104, 0.3);
    border-radius: 4px;
    background: rgba(10, 14, 39, 0.4);
}

/* ===== Random Walk ===== */
.random-walk-viz {
    width: 100%;
    border: 1px solid rgba(74, 85, 104, 0.3);
    border-radius: 4px;
    background: rgba(10, 14, 39, 0.6);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

#walkCanvas {
    width: 100%;
    height: auto;
    display: block;
}

.walk-controls {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.walk-btn {
    font-family: var(--font-data);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: transparent;
    border: 1px solid var(--cyan);
    color: var(--cyan);
    padding: 0.6rem 1.5rem;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.3s ease, color 0.3s ease;
}

.walk-btn:hover {
    background: var(--cyan);
    color: var(--bg);
}

.walk-stat {
    font-size: 0.75rem;
    color: var(--gray);
}

/* ===== Footer ===== */
#siteFooter {
    position: relative;
    z-index: 10;
    padding: 3rem 2rem;
    border-top: 1px solid rgba(74, 85, 104, 0.2);
}

.footer-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-domain {
    font-family: var(--font-headline);
    font-size: 1.2rem;
    color: var(--text);
}

.footer-note {
    font-size: 0.8rem;
    color: var(--gray);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .section {
        padding: 4rem 1.5rem;
    }

    .entropy-bars {
        gap: 1rem;
        height: 200px;
    }

    .stat-row {
        gap: 1.5rem;
    }

    .bayes-formula {
        font-size: 1rem;
    }

    .walk-controls {
        gap: 1rem;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .kinetic-title {
        font-size: 5rem;
    }

    .entropy-bars {
        gap: 0.5rem;
    }
}
