/* ============================================
   munj.uk - Underground Station Descent
   ============================================ */
:root {
    --obsidian-night: #0B0E13;
    --tunnel-black: #05070A;
    --station-slate: #0F1318;
    --sodium-amber: #D4A017;
    --filament-orange: #E8752A;
    --platform-cyan: #3B8EA5;
    --tile-white: #E8E4DE;
    --emergency-magenta: #C2185B;
    --seam-opacity: 0.15;
    --slate-border: rgba(42, 58, 79, 0.3);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
body {
    background: linear-gradient(180deg, var(--obsidian-night) 0%, var(--tunnel-black) 100%);
    color: var(--tile-white);
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.15rem);
    line-height: 1.65;
    overflow-x: hidden;
}

/* --- Grain Overlay --- */
.grain-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.04;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}

/* --- Scroll Progress --- */
.scroll-progress {
    position: fixed;
    right: 0;
    top: 0;
    width: 2px;
    height: 0%;
    background: var(--sodium-amber);
    z-index: 9998;
    transition: height 0.1s linear;
}

/* --- Amber Pulse --- */
.amber-pulse {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 0;
    height: 1px;
    background: var(--sodium-amber);
    z-index: 9997;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
}
.amber-pulse.active {
    animation: amberExpand 1s ease-out forwards;
}
@keyframes amberExpand {
    0% { width: 0; opacity: 1; }
    40% { width: 100vw; opacity: 1; }
    100% { width: 100vw; opacity: 0; }
}

/* --- Level Base --- */
.level {
    min-height: 100vh;
    position: relative;
    padding: clamp(2rem, 4vw, 4rem);
}
.level-1, .level-2, .level-3 {
    min-height: 120vh;
}

/* --- Bento Grid --- */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 2px;
    background: rgba(212, 160, 23, var(--seam-opacity));
    padding: 2px;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}
.bento-cell {
    background: var(--obsidian-night);
    padding: clamp(1rem, 2vw, 2rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    transition: background 0.3s ease;
}
.bento-cell:hover {
    background: rgba(15, 19, 24, 0.95);
}

/* --- Bento Variants --- */
.bento-grid--sparse {
    min-height: 80vh;
    align-content: center;
}
.bento-grid--concourse .bento-cell {
    border: 1px solid var(--slate-border);
}
.bento-grid--escalator {
    transform: skewY(-1.5deg);
}
.bento-grid--escalator .bento-cell {
    transform: skewY(1.5deg);
}
.bento-grid--platform {
    grid-auto-rows: minmax(80px, auto);
}
.bento-cell--sm {
    padding: clamp(0.6rem, 1vw, 1rem);
    display: flex;
    align-items: center;
    justify-content: center;
}
.bento-cell--alert {
    border: 1px solid rgba(194, 24, 91, 0.3);
}
.bento-cell--moire {
    background:
        repeating-linear-gradient(45deg, transparent 0px, transparent 3px, rgba(232, 228, 222, 0.03) 3px, rgba(232, 228, 222, 0.03) 4px),
        repeating-linear-gradient(47deg, transparent 0px, transparent 3px, rgba(232, 228, 222, 0.03) 3px, rgba(232, 228, 222, 0.03) 4px),
        var(--obsidian-night);
}
.bento-grid--ghost {
    background: transparent;
    gap: 8px;
}
.bento-cell--ghost {
    background: var(--station-slate);
    border: none;
}

/* --- Typography --- */
.level-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4rem);
    letter-spacing: 0.02em;
    line-height: 1.1;
    color: var(--tile-white);
    margin-bottom: 1rem;
}
.level-title--hero {
    font-size: clamp(3.5rem, 8vw, 6rem);
    letter-spacing: 0.03em;
}
.level-title--sm {
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    margin-bottom: 0;
}
/* Kinetic character spans */
.level-title span {
    display: inline-block;
    clip-path: inset(0 100% 0 0);
    transition: clip-path 0.4s cubic-bezier(0.16, 1, 0.3, 1), letter-spacing 0.1s ease;
}
.level-title.revealed span {
    clip-path: inset(0 0% 0 0);
}

.body-text {
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.95rem, 1.3vw, 1.1rem);
    line-height: 1.65;
    color: var(--tile-white);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin-bottom: 1rem;
}
.body-text.visible {
    opacity: 1;
    transform: translateY(0);
}
.body-text--micro {
    font-size: clamp(0.8rem, 1vw, 0.9rem);
}
.body-text--intimate {
    font-size: clamp(0.9rem, 1.1vw, 1rem);
    opacity: 0.85;
}

.system-text {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    letter-spacing: 0.05em;
    color: var(--sodium-amber);
    opacity: 0.7;
    display: block;
    line-height: 1.8;
    text-shadow: 0 0 8px rgba(212, 160, 23, 0.4);
}
.system-text--alert {
    color: var(--emergency-magenta);
    text-shadow: 0 0 8px rgba(194, 24, 91, 0.4);
}

.data-glyph {
    font-size: 2rem;
    color: var(--platform-cyan);
    opacity: 0.5;
}

/* --- Threshold Line --- */
.threshold-line {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--sodium-amber);
    opacity: 0.3;
}

/* --- Dot Matrix --- */
.dot-matrix {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 4px;
}
.dot-matrix--sm {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}
.dot-matrix span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--sodium-amber);
    opacity: 0.2;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* --- Pulse Dot --- */
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--filament-orange);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.3); }
}

/* --- SVG Fragments --- */
.roundel-fragment, .pipe-fragment {
    width: 80%;
    max-width: 100px;
    opacity: 0.6;
}
.draw-path {
    transition: stroke-dashoffset 0.8s ease;
}
.roundel-fragment.visible .draw-path,
.pipe-fragment.visible .draw-path {
    stroke-dashoffset: 0;
}

/* --- Level 4: Tunnel --- */
.level-4 {
    background: var(--tunnel-black);
    display: flex;
    align-items: center;
    justify-content: center;
}
.tunnel-column {
    max-width: 540px;
    text-align: left;
}

/* --- Level 5: Ghost Station --- */
.level-5 {
    position: relative;
}
.ghost-glow {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: transparent;
    z-index: 0;
}

/* --- Reveal System --- */
[data-reveal] {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}
[data-reveal].visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 768px) {
    .bento-grid {
        grid-template-columns: repeat(8, 1fr);
    }
    .bento-cell {
        grid-column: span 4 !important;
    }
    .bento-cell--title {
        grid-column: 1 / -1 !important;
    }
    .bento-grid--escalator {
        transform: none;
    }
    .bento-grid--escalator .bento-cell {
        transform: none;
    }
    .bento-grid--platform .bento-cell--sm {
        grid-column: span 4 !important;
    }
}
