/* ========================================
   haskeller.net — Avant-Garde Mathematical Theater
   Gold-Black Luxury / Bento-Box Layout
   ======================================== */

/* CSS Custom Properties */
:root {
    --gold: #d4a017;
    --gold-burnished: #c9a84c;
    --bronze: #8b7355;
    --black: #0a0a0a;
    --charcoal: #141414;
    --parchment: #e8dcc8;
    --ivory: #a89b8c;
    --amber: #f5c518;
    --magenta: #d4175a;
    --scroll-weight: 300;
    --scroll-progress: 0;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--black);
    color: var(--parchment);
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.2vw, 1.25rem);
    line-height: 1.72;
    overflow-x: hidden;
}

/* ========================================
   Persistent Lambda
   ======================================== */
.persistent-lambda {
    position: fixed;
    top: 24px;
    left: 28px;
    font-family: 'Fraunces', serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--gold);
    z-index: 1000;
    animation: lambdaPulse 4s ease-in-out infinite;
    text-shadow: 0 0 40px rgba(212, 160, 23, 0.3);
    cursor: default;
    user-select: none;
}

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

/* ========================================
   Chamber Layout
   ======================================== */
.chamber {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

/* ========================================
   Bento Grid System
   ======================================== */
.bento-grid {
    display: grid;
    gap: 2px;
    max-width: 1400px;
    width: 100%;
    background-color: var(--gold);
}

.bento-cell {
    background-color: var(--black);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
    opacity: 0;
    animation: cellReveal 0.6s ease-out forwards;
}

@keyframes cellReveal {
    0% {
        opacity: 0;
        transform: scale(0.95);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ========================================
   Hero Bento Grid (4x3)
   ======================================== */
.hero-grid {
    grid-template-columns: 2fr 1fr 1fr 1fr;
    grid-template-rows: auto auto auto;
}

.hero-title-cell {
    grid-column: 1 / 3;
    grid-row: 1 / 3;
    padding: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-title {
    font-family: 'Fraunces', serif;
    font-size: clamp(3rem, 8vw, 7rem);
    font-weight: 900;
    font-variation-settings: 'opsz' 144, 'WONK' 1;
    color: var(--gold);
    text-shadow: 0 0 40px rgba(212, 160, 23, 0.3);
    letter-spacing: -0.02em;
}

.hero-title .char {
    display: inline-block;
    opacity: 0;
}

.hero-title .char.revealed {
    opacity: 1;
    transition: opacity 0s;
}

.hero-type-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.hero-counter-cell {
    display: flex;
    align-items: center;
    justify-content: center;
}

.type-signature {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-feature-settings: 'liga' 1, 'calt' 1;
    font-size: clamp(0.85rem, 1vw, 1.1rem);
    color: var(--gold-burnished);
    white-space: nowrap;
    position: relative;
}

.type-signature[data-glitch='true']::before,
.type-signature[data-glitch='true']::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
}

.type-signature[data-glitch='true']::before {
    color: var(--magenta);
    animation: glitchFlicker 12s infinite;
}

.type-signature[data-glitch='true']::after {
    color: #1a6b4a;
    animation: glitchFlicker 15s infinite 2s;
}

@keyframes glitchFlicker {
    0%, 97%, 100% {
        opacity: 0;
        transform: translate(0, 0);
    }
    97.5% {
        opacity: 0.8;
        transform: translate(3px, 0);
    }
    98.5% {
        opacity: 0.8;
        transform: translate(-2px, 0);
    }
    99% {
        opacity: 0;
        transform: translate(0, 0);
    }
}

/* ========================================
   Philosophy Bento Grid (3x2)
   ======================================== */
.philosophy-grid {
    grid-template-columns: 1.4fr 1fr 0.6fr;
    grid-template-rows: auto auto;
}

.philosophy-text-cell.large-cell {
    grid-row: 1 / 3;
}

.section-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--bronze);
    margin-bottom: 16px;
    display: block;
}

.philosophy-text {
    font-family: 'Fraunces', serif;
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    font-weight: var(--scroll-weight);
    font-variation-settings: 'opsz' 36, 'WONK' 1;
    color: var(--parchment);
    line-height: 1.6;
}

.philosophy-spiral-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}

.recursion-spiral {
    overflow: visible;
}

.recursion-spiral path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 8s ease-out;
}

.recursion-spiral.animate path {
    stroke-dashoffset: 0;
}

.philosophy-counter-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ========================================
   Counters
   ======================================== */
.counter {
    font-family: 'Fraunces', serif;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--amber);
    text-shadow: 0 0 30px rgba(245, 197, 24, 0.4);
}

.counter-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--bronze);
}

/* ========================================
   Expression Bento Grid (2x4 tall)
   ======================================== */
.expression-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, auto);
}

.expression-code-cell {
    padding: 32px 24px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    transition: background-color 0.3s ease;
    position: relative;
}

.expression-code-cell:hover {
    background-color: var(--charcoal);
}

.code-art {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-feature-settings: 'liga' 1, 'calt' 1;
    font-size: clamp(0.85rem, 1vw, 1.1rem);
    color: var(--gold-burnished);
    background-color: #0d0d0d;
    text-shadow: 0 0 20px rgba(201, 168, 76, 0.3);
    transition: text-shadow 0.3s ease;
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
}

.expression-code-cell:hover .code-art {
    text-shadow: 0 0 30px rgba(201, 168, 76, 0.8);
}

.code-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--bronze);
}

.cell-decoration {
    position: absolute;
    top: 12px;
    right: 12px;
    opacity: 0.25;
    transition: opacity 0.3s ease;
}

.expression-code-cell:hover .cell-decoration {
    opacity: 0.7;
}

/* Glitch effects on hover */
.expression-code-cell[data-glitch-type='chromatic']:hover .code-art {
    animation: chromaticAberration 0.2s steps(2) infinite;
}

.expression-code-cell[data-glitch-type='scanline']:hover::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 2px,
        rgba(212, 160, 23, 0.03) 2px,
        rgba(212, 160, 23, 0.03) 4px
    );
    pointer-events: none;
    animation: scanlineShift 0.5s steps(4) infinite;
}

.expression-code-cell[data-glitch-type='jitter']:hover .code-art {
    animation: jitter 0.1s steps(3) infinite;
}

@keyframes chromaticAberration {
    0% { text-shadow: 2px 0 var(--magenta), -2px 0 #1a6b4a, 0 0 20px rgba(201, 168, 76, 0.8); }
    50% { text-shadow: -1px 0 var(--magenta), 1px 0 #1a6b4a, 0 0 20px rgba(201, 168, 76, 0.8); }
    100% { text-shadow: 2px 0 var(--magenta), -2px 0 #1a6b4a, 0 0 20px rgba(201, 168, 76, 0.8); }
}

@keyframes scanlineShift {
    0% { transform: translateY(0); }
    25% { transform: translateY(1px); }
    50% { transform: translateY(0); }
    75% { transform: translateY(-1px); }
    100% { transform: translateY(0); }
}

@keyframes jitter {
    0% { transform: translate(0, 0); }
    33% { transform: translate(1px, -1px); }
    66% { transform: translate(-1px, 1px); }
    100% { transform: translate(0, 0); }
}

.expression-counter-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ========================================
   Community Bento Grid (3x3)
   ======================================== */
.community-grid {
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-rows: auto auto auto;
}

.community-link-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
}

.community-link {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-size: 0.85rem;
    color: var(--parchment);
    text-decoration: none;
    position: relative;
    background-image: linear-gradient(var(--gold), var(--gold));
    background-size: 0% 1px;
    background-position: left bottom;
    background-repeat: no-repeat;
    transition: background-size 0.4s ease, color 0.3s ease;
    padding-bottom: 2px;
}

.community-link:hover {
    color: var(--gold);
    background-size: 100% 1px;
}

.monad-bullet {
    flex-shrink: 0;
}

.community-lambda-cell {
    grid-column: 2;
    grid-row: 1 / 4;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

.community-counter-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ========================================
   Glitch Lambda
   ======================================== */
.glitch-lambda {
    position: relative;
    font-family: 'Fraunces', serif;
    font-size: clamp(12rem, 20vw, 20rem);
    font-weight: 900;
    line-height: 1;
}

.lambda-base {
    color: var(--gold);
    text-shadow: 0 0 60px rgba(212, 160, 23, 0.4);
    position: relative;
    z-index: 2;
}

.lambda-glitch {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    mix-blend-mode: screen;
}

.lambda-r {
    color: var(--gold);
    animation: glitchShiftR 6s ease-in-out infinite;
}

.lambda-g {
    color: var(--magenta);
    animation: glitchShiftG 6s ease-in-out infinite 0.5s;
}

.lambda-b {
    color: #1a6b4a;
    animation: glitchShiftB 6s ease-in-out infinite 1s;
}

@keyframes glitchShiftR {
    0%, 40%, 60%, 100% { transform: translate(0, 0); opacity: 0; }
    45% { transform: translate(3px, 0); opacity: 0.7; }
    55% { transform: translate(-2px, 0); opacity: 0.7; }
}

@keyframes glitchShiftG {
    0%, 40%, 60%, 100% { transform: translate(0, 0); opacity: 0; }
    45% { transform: translate(-3px, 1px); opacity: 0.5; }
    55% { transform: translate(2px, -1px); opacity: 0.5; }
}

@keyframes glitchShiftB {
    0%, 40%, 60%, 100% { transform: translate(0, 0); opacity: 0; }
    45% { transform: translate(2px, -2px); opacity: 0.4; }
    55% { transform: translate(-3px, 1px); opacity: 0.4; }
}

/* ========================================
   Void Separators
   ======================================== */
.void-separator {
    height: 30vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    background-color: var(--black);
}

.geometric-shape {
    opacity: 0.25;
    transition: opacity 0.6s ease;
}

.void-separator.in-view .geometric-shape {
    opacity: 0.7;
}

.lambda-triangle {
    animation: slowRotate 20s linear infinite;
}

.monad-circle {
    animation: slowRotate 15s linear infinite;
}

.orbiting-circle {
    transform-origin: 50px 50px;
    animation: orbit 4s linear infinite;
}

@keyframes slowRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes orbit {
    from { transform: rotate(0deg) translateX(35px) rotate(0deg); }
    to { transform: rotate(360deg) translateX(35px) rotate(-360deg); }
}

.orbiting-circle {
    transform-origin: 50px 50px;
}

.void-final {
    padding-bottom: 80px;
}

.final-text {
    font-family: 'Fraunces', serif;
    font-size: clamp(1rem, 2vw, 1.5rem);
    font-weight: 300;
    font-variation-settings: 'opsz' 36, 'WONK' 1;
    color: var(--bronze);
    text-align: center;
    opacity: 0.7;
}

/* ========================================
   Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .lambda-triangle,
    .monad-circle,
    .orbiting-circle {
        animation: none;
    }
    
    .lambda-r, .lambda-g, .lambda-b {
        animation: none;
        opacity: 0;
    }
    
    .type-signature[data-glitch='true']::before,
    .type-signature[data-glitch='true']::after {
        animation: none;
    }
    
    .expression-code-cell[data-glitch-type='chromatic']:hover .code-art,
    .expression-code-cell[data-glitch-type='jitter']:hover .code-art {
        animation: none;
    }
    
    .expression-code-cell[data-glitch-type='scanline']:hover::after {
        animation: none;
    }
    
    .persistent-lambda {
        animation: none;
        opacity: 0.8;
    }
    
    .bento-cell {
        animation: none;
        opacity: 1;
    }
    
    .counter {
        /* Show final values immediately */
    }
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .hero-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
    }
    
    .hero-title-cell {
        grid-column: 1 / -1;
        grid-row: auto;
    }
    
    .philosophy-grid {
        grid-template-columns: 1fr;
    }
    
    .philosophy-text-cell.large-cell {
        grid-row: auto;
    }
    
    .expression-grid {
        grid-template-columns: 1fr;
    }
    
    .community-grid {
        grid-template-columns: 1fr;
    }
    
    .community-lambda-cell {
        grid-column: 1;
        grid-row: auto;
        min-height: 200px;
    }
    
    .glitch-lambda {
        font-size: 8rem;
    }
}
