/* mosoon.xyz // glitch-core stylesheet
   Palette: high-contrast B&W (Void Black, Pure White, Glitch Gray, Scan Dark, Fragment White, Decay Gray)
   Type:    Press Start 2P (Google Fonts), IBM Plex Mono (Google Fonts), VT323 (Google Fonts)
   Motifs:  noise-grain overlay, glitch bursts, scanline displacement, masonry, digital decay
*/

:root {
    --void-black: #0A0A0A;
    --pure-white: #F0F0F0;
    --glitch-gray: #808080;
    --scan-dark: #1A1A1A;
    --fragment-white: #FFFFFF;
    --decay-gray: #404040;

    --gap: 4px;
    --pad: 16px;

    --font-pixel: "Press Start 2P", "Courier New", monospace;
    --font-mono: "IBM Plex Mono", "Courier New", monospace;
    --font-corrupt: "VT323", "Courier New", monospace;
}

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

html, body {
    background: var(--void-black);
    color: var(--pure-white);
    font-family: var(--font-mono);
    font-size: clamp(12px, 0.8vw, 14px);
    line-height: 1.6;
    overflow-x: hidden;
    cursor: crosshair;
}

body {
    position: relative;
    min-height: 100vh;
}

/* The SVG that hosts the animated turbulence; hidden visually but used for filter */
.noise-svg {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    z-index: -10;
}

/* Animated noise overlay sitting above all content */
.noise-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9000;
    opacity: 0.12;
    mix-blend-mode: difference;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 240px 240px;
    animation: noiseShift 0.4s steps(6) infinite;
}

@keyframes noiseShift {
    0%   { background-position:   0px   0px; }
    20%  { background-position: -80px  40px; }
    40%  { background-position:  60px -90px; }
    60%  { background-position: -120px 30px; }
    80%  { background-position:  20px  70px; }
    100% { background-position:   0px   0px; }
}

/* Scanlines — fine horizontal stripes */
.scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9100;
    background-image: repeating-linear-gradient(
        to bottom,
        rgba(10, 10, 10, 0)     0px,
        rgba(10, 10, 10, 0)     2px,
        rgba(10, 10, 10, 0.18)  3px,
        rgba(10, 10, 10, 0)     4px
    );
    mix-blend-mode: multiply;
}

/* Hero ------------------------------------------------------------------- */
.hero {
    position: relative;
    height: 100vh;
    width: 100%;
    background: var(--void-black);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--decay-gray);
}

.hero-inner {
    position: relative;
    text-align: center;
    padding: 24px;
    z-index: 2;
}

/* Logotype with channel-separation layers for glitch */
.logotype {
    position: relative;
    display: inline-block;
    font-family: var(--font-pixel);
    font-weight: 400;
    font-size: clamp(16px, 4.5vw, 56px);
    letter-spacing: 0.04em;
    color: var(--pure-white);
    text-transform: lowercase;
    line-height: 1;
    user-select: none;
}

.logo-layer {
    display: block;
    grid-area: 1 / 1;
}

.logotype {
    display: grid;
    place-items: center;
}

.logo-base {
    position: relative;
    z-index: 3;
    animation: logoBaseGlitch 3.4s steps(1) infinite;
}

.logo-r,
.logo-b {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    mix-blend-mode: screen;
}

.logo-r {
    color: #ffffff;
    text-shadow: 2px 0 0 #2a2a2a;
    transform: translate(2px, 0);
    animation: logoR 2.8s steps(1) infinite;
}

.logo-b {
    color: #ffffff;
    text-shadow: -2px 0 0 #2a2a2a;
    transform: translate(-2px, 0);
    animation: logoB 2.6s steps(1) infinite;
}

@keyframes logoBaseGlitch {
    0%, 92%, 100% { transform: translate(0, 0); clip-path: inset(0); }
    93%           { transform: translate(-2px, 0); clip-path: inset(20% 0 60% 0); }
    94%           { transform: translate(3px, 0);  clip-path: inset(60% 0 10% 0); }
    95%           { transform: translate(-1px, 0); clip-path: inset(40% 0 30% 0); }
    96%           { transform: translate(0, 0);    clip-path: inset(0); }
}

@keyframes logoR {
    0%, 90%, 100% { transform: translate(2px, 0);  clip-path: inset(0); }
    91%           { transform: translate(6px, -1px); clip-path: inset(10% 0 70% 0); }
    93%           { transform: translate(-4px, 1px); clip-path: inset(50% 0 20% 0); }
    95%           { transform: translate(2px, 0);  clip-path: inset(0); }
}

@keyframes logoB {
    0%, 88%, 100% { transform: translate(-2px, 0); clip-path: inset(0); }
    89%           { transform: translate(-6px, 1px); clip-path: inset(30% 0 40% 0); }
    91%           { transform: translate(4px, -1px); clip-path: inset(70% 0 10% 0); }
    94%           { transform: translate(-2px, 0); clip-path: inset(0); }
}

.hero-meta {
    margin-top: 36px;
    font-family: var(--font-mono);
    font-size: clamp(10px, 0.85vw, 13px);
    letter-spacing: 0.12em;
    color: var(--glitch-gray);
    text-transform: uppercase;
}

.meta-bracket {
    color: var(--pure-white);
    margin: 0 6px;
}

.hero-pulse {
    margin-top: 20px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-corrupt);
    font-size: 18px;
    color: var(--pure-white);
    letter-spacing: 0.06em;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: var(--pure-white);
    display: inline-block;
    animation: pulse 1.4s steps(2) infinite;
}

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

.pulse-line {
    border-left: 1px solid var(--decay-gray);
    padding-left: 10px;
}

/* Viewport-wide glitch burst overlay ------------------------------------- */
.viewport-glitch {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9300;
    background: transparent;
    opacity: 0;
}

.viewport-glitch.fire {
    animation: viewportGlitch 0.22s steps(4) 1;
}

@keyframes viewportGlitch {
    0% {
        opacity: 1;
        background:
            linear-gradient(transparent 0 30%, rgba(240,240,240,0.85) 30% 32%, transparent 32% 60%, rgba(240,240,240,0.55) 60% 61%, transparent 61% 100%);
        transform: translateX(-4px);
        filter: invert(1);
    }
    25% {
        opacity: 1;
        background:
            linear-gradient(transparent 0 18%, rgba(240,240,240,0.65) 18% 19%, transparent 19% 75%, rgba(240,240,240,0.7) 75% 78%, transparent 78% 100%);
        transform: translateX(4px);
        filter: invert(0);
    }
    50% {
        opacity: 1;
        background:
            linear-gradient(transparent 0 50%, rgba(10,10,10,0.65) 50% 53%, transparent 53% 100%);
        transform: translateX(-2px);
        filter: invert(1);
    }
    75% {
        opacity: 1;
        background:
            linear-gradient(transparent 0 80%, rgba(240,240,240,0.75) 80% 82%, transparent 82% 100%);
        transform: translateX(3px);
        filter: invert(0);
    }
    100% {
        opacity: 0;
        background: transparent;
        transform: translateX(0);
        filter: invert(0);
    }
}

/* Masonry grid ----------------------------------------------------------- */
.masonry {
    column-count: 4;
    column-gap: var(--gap);
    padding: var(--gap);
    background: var(--void-black);
}

@media (max-width: 1100px) {
    .masonry { column-count: 3; }
}

@media (max-width: 760px) {
    .masonry { column-count: 2; }
}

@media (max-width: 460px) {
    .masonry { column-count: 1; }
}

.frag {
    break-inside: avoid;
    margin: 0 0 var(--gap) 0;
    padding: var(--pad);
    background: var(--void-black);
    color: var(--pure-white);
    border: 1px solid var(--decay-gray);
    position: relative;
    overflow: hidden;
}

.frag--invert {
    background: var(--fragment-white);
    color: var(--void-black);
    border-color: var(--scan-dark);
}

.frag--invert .frag-id,
.frag--invert .frag-stamp {
    color: var(--scan-dark);
}

.frag--invert .frag-glyph {
    color: var(--decay-gray);
}

.frag--lg { padding: 22px; }
.frag--sm { padding: 12px; }

.frag-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--glitch-gray);
    border-bottom: 1px dashed currentColor;
    padding-bottom: 6px;
}

.frag-id {
    font-weight: 700;
}

.frag-title {
    font-family: var(--font-pixel);
    font-size: clamp(12px, 1.05vw, 16px);
    line-height: 1.3;
    margin-bottom: 12px;
    letter-spacing: 0.02em;
    word-break: break-word;
}

.frag--decay .frag-title {
    font-family: var(--font-corrupt);
    font-size: 22px;
    color: var(--decay-gray);
    letter-spacing: 0.04em;
}

.frag-body {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    margin-bottom: 8px;
}

.frag-body--mono {
    font-family: var(--font-corrupt);
    font-size: 16px;
    line-height: 1.45;
    color: inherit;
    background: var(--scan-dark);
    color: var(--pure-white);
    padding: 10px 12px;
    margin-top: 10px;
    border-left: 2px solid var(--pure-white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
}

.frag--invert .frag-body--mono {
    background: var(--scan-dark);
    color: var(--pure-white);
    border-left-color: var(--scan-dark);
}

.frag-body--corrupt {
    font-family: var(--font-corrupt);
    font-size: 18px;
    letter-spacing: 0.06em;
    color: var(--decay-gray);
}

.frag-glyph {
    margin-top: 12px;
    font-family: var(--font-pixel);
    font-size: 10px;
    letter-spacing: 0.1em;
    color: var(--glitch-gray);
}

/* Digital-decay corruption mask on .frag--decay */
.frag--decay {
    -webkit-mask-image: linear-gradient(
        to bottom,
        #000 0%,
        #000 60%,
        transparent 61%,
        #000 63%,
        #000 70%,
        transparent 71%,
        #000 73%,
        #000 100%
    );
    mask-image: linear-gradient(
        to bottom,
        #000 0%,
        #000 60%,
        transparent 61%,
        #000 63%,
        #000 70%,
        transparent 71%,
        #000 73%,
        #000 100%
    );
}

.decay-bars {
    display: flex;
    gap: 2px;
    margin-top: 12px;
    align-items: flex-end;
    height: 18px;
}

.decay-bars span {
    flex: 1;
    background: var(--decay-gray);
    height: 100%;
    animation: decayBar 1.1s steps(4) infinite;
    transform-origin: bottom;
}

.decay-bars span:nth-child(2) { animation-delay: 0.1s; }
.decay-bars span:nth-child(3) { animation-delay: 0.25s; background: var(--glitch-gray); }
.decay-bars span:nth-child(4) { animation-delay: 0.4s; }
.decay-bars span:nth-child(5) { animation-delay: 0.6s; background: var(--pure-white); }

@keyframes decayBar {
    0%   { transform: scaleY(0.2); }
    50%  { transform: scaleY(1); }
    100% { transform: scaleY(0.5); }
}

/* Per-fragment scanline displacement (applied randomly via JS) */
.frag.scan-displace {
    animation: scanDisplace 0.45s steps(6) 1;
}

@keyframes scanDisplace {
    0%   { clip-path: inset(0); transform: translateX(0); }
    10%  { clip-path: inset(30% 0 60% 0); transform: translateX(-3px); }
    20%  { clip-path: inset(0); transform: translateX(0); }
    30%  { clip-path: inset(60% 0 25% 0); transform: translateX(2px); }
    40%  { clip-path: inset(0); transform: translateX(0); }
    50%  { clip-path: inset(15% 0 75% 0); transform: translateX(-4px); }
    60%  { clip-path: inset(0); transform: translateX(0); }
    100% { clip-path: inset(0); transform: translateX(0); }
}

/* Per-fragment quick invert flicker */
.frag.invert-flicker {
    animation: invertFlicker 0.18s steps(2) 1;
}

@keyframes invertFlicker {
    0%   { filter: invert(0); }
    50%  { filter: invert(1); }
    100% { filter: invert(0); }
}

/* HUD -------------------------------------------------------------------- */
.hud {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9200;
    background: rgba(10, 10, 10, 0.85);
    border: 1px solid var(--decay-gray);
    padding: 8px 10px;
    font-family: var(--font-corrupt);
    font-size: 16px;
    color: var(--pure-white);
    min-width: 150px;
    backdrop-filter: blur(2px);
}

.hud-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    line-height: 1.2;
}

.hud-key {
    color: var(--glitch-gray);
    letter-spacing: 0.1em;
}

.hud-val {
    color: var(--pure-white);
    font-weight: 700;
}

.hud-val.flash {
    animation: hudFlash 0.18s steps(2) 1;
}

@keyframes hudFlash {
    0%   { background: var(--pure-white); color: var(--void-black); }
    100% { background: transparent;       color: var(--pure-white); }
}

/* Footer ----------------------------------------------------------------- */
.footer {
    padding: 24px 16px 32px;
    background: var(--void-black);
    color: var(--glitch-gray);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    border-top: 1px solid var(--decay-gray);
}

.footer-text {
    color: var(--pure-white);
}

.footer-sep {
    margin: 0 10px;
    color: var(--decay-gray);
}

/* Hero stabilize state — used by JS once intro is done */
.hero.stable .logo-base { animation-duration: 5s; }
.hero.stable .logo-r,
.hero.stable .logo-b    { opacity: 0.55; }

/* Intro mass glitch on first paint */
.hero.intro .logo-base  { animation: introGlitch 1.5s steps(8) 1; }
.hero.intro .logo-r     { animation: introR 1.5s steps(8) 1; }
.hero.intro .logo-b     { animation: introB 1.5s steps(8) 1; }

@keyframes introGlitch {
    0%   { transform: translate(-12px, -8px); clip-path: inset(20% 0 60% 0); opacity: 0; }
    10%  { transform: translate( 14px,  4px); clip-path: inset(50% 0 20% 0); opacity: 0.4; }
    20%  { transform: translate(-10px,  6px); clip-path: inset(70% 0 10% 0); opacity: 0.5; }
    30%  { transform: translate(  6px, -6px); clip-path: inset(10% 0 80% 0); opacity: 0.7; }
    40%  { transform: translate( -4px,  2px); clip-path: inset(40% 0 40% 0); opacity: 0.8; }
    60%  { transform: translate(  2px,  0);   clip-path: inset(0); opacity: 1; }
    100% { transform: translate(  0,    0);   clip-path: inset(0); opacity: 1; }
}

@keyframes introR {
    0%   { transform: translate(20px, 0); opacity: 0; }
    50%  { transform: translate(8px, 0);  opacity: 0.7; }
    100% { transform: translate(2px, 0);  opacity: 1; }
}

@keyframes introB {
    0%   { transform: translate(-20px, 0); opacity: 0; }
    50%  { transform: translate(-8px, 0);  opacity: 0.7; }
    100% { transform: translate(-2px, 0);  opacity: 1; }
}

/* Fragment entrance — opacity 0 to 1, 100ms, no easing (per design) */
.frag {
    opacity: 0;
    transition: opacity 100ms linear;
}

.frag.visible {
    opacity: 1;
}

/* Hover: a quick channel-shift ghost */
.frag:hover {
    box-shadow:
         3px 0 0 rgba(240,240,240,0.18),
        -3px 0 0 rgba(64,64,64,0.5);
}

.frag--invert:hover {
    box-shadow:
         3px 0 0 rgba(10,10,10,0.45),
        -3px 0 0 rgba(128,128,128,0.45);
}
