/* p9r.xyz — Mid-century modern through corrupted transmission */
/* Colors from DESIGN.md palette */
/* Deep Espresso: #2B1D14 | Fired Clay: #C4572A | Saharan Sand: #E8CDA8 */
/* Burnt Sienna Glow: #D97B3D | Parchment White: #F2EAD9 | Charred Umber: #1E1209 */
/* Signal Blue: #3B7EA1 | Patina Green: #5A9E6F */

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: #2B1D14;
    color: #F2EAD9;
    font-family: 'Lora', serif;
    font-size: clamp(16px, 1.4vw, 20px);
    line-height: 1.65;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
}

/* Scanline overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(43, 29, 20, 0.04) 1px,
        rgba(43, 29, 20, 0.04) 2px
    );
    pointer-events: none;
    z-index: 9999;
}

/* Signal Grid */
.signal-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(80px, 1fr);
    gap: 4px;
    min-height: 100vh;
    padding: 4px;
    position: relative;
}

/* Base block styles */
.block {
    position: relative;
    overflow: hidden;
    transform: scale(0.97);
    opacity: 0.85;
    transition: transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 400ms ease;
}

.block.in-focus {
    transform: scale(1.0);
    opacity: 1;
}

.block.adjacent-dim {
    opacity: 0.7;
    transform: scale(0.97) translate(var(--shift-x, 0), var(--shift-y, 0));
}

/* Negative blocks */
.negative-block {
    background-color: #2B1D14;
    opacity: 1;
    transform: scale(1);
}

/* Text blocks */
.text-block {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: clamp(24px, 4vw, 64px);
}

.text-block.dark {
    background-color: #2B1D14;
}

.text-block.light {
    background-color: #E8CDA8;
    color: #1E1209;
}

.text-block.light .mono-caption {
    color: #1E1209;
    opacity: 0.5;
}

/* Typography */
.display-heading {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(36px, 6vw, 96px);
    font-weight: 400;
    letter-spacing: -0.015em;
    line-height: 1.08;
    color: #F2EAD9;
    margin: 0;
}

.text-block.light .display-heading {
    color: #1E1209;
}

.body-text {
    font-family: 'Lora', serif;
    font-size: clamp(16px, 1.4vw, 20px);
    line-height: 1.65;
    letter-spacing: 0.01em;
    max-width: 38em;
    margin-top: 0.75em;
}

.light-text {
    color: #F2EAD9;
}

.italic-pull {
    font-family: 'Libre Baskerville', serif;
    font-style: italic;
    font-size: clamp(20px, 3vw, 36px);
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.mono-caption {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #F2EAD9;
    opacity: 0.4;
    margin-bottom: 1em;
}

/* Pattern blocks */
.pattern-block {
    position: relative;
}

.diamond-hatching {
    background-color: #E8CDA8;
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 10px,
            rgba(196, 87, 42, 0.3) 10px,
            rgba(196, 87, 42, 0.3) 12px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent,
            transparent 10px,
            rgba(196, 87, 42, 0.3) 10px,
            rgba(196, 87, 42, 0.3) 12px
        );
}

.dot-matrix {
    background-color: #E8CDA8;
    background-image: radial-gradient(
        circle,
        rgba(196, 87, 42, 0.2) 2px,
        transparent 2px
    );
    background-size: 16px 16px;
}

.concentric-rects {
    background-color: #2B1D14;
    display: flex;
    align-items: center;
    justify-content: center;
}

.concentric-inner {
    position: relative;
    width: 80%;
    height: 80%;
}

.concentric-inner div {
    position: absolute;
    border: 2px solid #C4572A;
}

.concentric-inner div:nth-child(1) {
    inset: 0%;
}

.concentric-inner div:nth-child(2) {
    inset: 10%;
    border-color: #D97B3D;
}

.concentric-inner div:nth-child(3) {
    inset: 20%;
}

.concentric-inner div:nth-child(4) {
    inset: 30%;
    border-color: #D97B3D;
}

.concentric-inner div:nth-child(5) {
    inset: 40%;
}

/* Watermark layer */
.watermark-layer {
    position: absolute;
    inset: 0;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 48 48' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='8' y='4' width='4' height='40' fill='%23F2EAD9'/%3E%3Crect x='12' y='4' width='16' height='4' fill='%23F2EAD9'/%3E%3Crect x='12' y='20' width='16' height='4' fill='%23F2EAD9'/%3E%3Crect x='28' y='4' width='4' height='20' fill='%23F2EAD9'/%3E%3C/svg%3E");
    background-size: 48px 48px;
    pointer-events: none;
}

/* Glitch blocks */
.glitch-block {
    background-color: #2B1D14;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.hero-glyph {
    z-index: 2;
}

.glyph-container {
    width: 240px;
    height: 240px;
    position: relative;
}

.glyph-small .p9r-glyph,
.glyph-small {
    width: 80px;
    height: 80px;
}

.p9r-glyph {
    width: 100%;
    height: 100%;
    filter: drop-shadow(2px 0 0 rgba(196, 87, 42, 0.6))
            drop-shadow(-2px 0 0 rgba(59, 126, 161, 0.4));
}

.glitch-text {
    font-family: 'Libre Baskerville', serif;
    font-style: italic;
    font-size: clamp(36px, 5vw, 72px);
    color: #F2EAD9;
    position: relative;
    letter-spacing: -0.015em;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch-text::before {
    color: #C4572A;
    left: 2px;
    top: -1px;
    opacity: 0.7;
    z-index: -1;
}

.glitch-text::after {
    color: #3B7EA1;
    left: -2px;
    top: 1px;
    opacity: 0.5;
    z-index: -1;
}

/* Glitch burst motif */
.glitch-burst {
    position: absolute;
    display: flex;
    gap: 3px;
}

.glitch-burst-tl {
    top: 12px;
    left: 12px;
}

.glitch-burst-br {
    bottom: 12px;
    right: 12px;
}

.glitch-burst span {
    display: block;
    width: 8px;
    height: 2px;
}

.glitch-burst span:nth-child(odd) {
    background-color: #3B7EA1;
    transform: rotate(3deg);
}

.glitch-burst span:nth-child(even) {
    background-color: #5A9E6F;
    transform: rotate(-2deg);
}

/* Chevron dividers */
.chevron-divider {
    background: transparent;
    display: flex;
    align-items: center;
    opacity: 1;
    transform: scale(1);
}

.chevron-svg {
    width: 100%;
    height: 100%;
}

/* Footer */
.footer-block {
    background-color: #2B1D14;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 1;
    transform: scale(1);
}

.footer-timestamp {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #F2EAD9;
    opacity: 0.3;
}

/* Navigation chevron */
.nav-chevron {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.chevron-icon {
    width: 32px;
    height: 32px;
    cursor: pointer;
    position: relative;
}

.chevron-diamond {
    width: 24px;
    height: 24px;
    background-color: #C4572A;
    transform: rotate(45deg);
    position: absolute;
    top: 4px;
    left: 4px;
    transition: transform 300ms ease, background-color 200ms ease;
}

.nav-chevron:hover .chevron-diamond,
.nav-chevron.active .chevron-diamond {
    transform: rotate(45deg) scale(1.2);
    background-color: #D97B3D;
}

.nav-labels {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 400ms ease, opacity 300ms ease;
}

.nav-chevron:hover .nav-labels,
.nav-chevron.active .nav-labels {
    max-height: 200px;
    opacity: 1;
}

.nav-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #F2EAD9;
    text-decoration: none;
    padding: 4px 8px;
    background-color: rgba(43, 29, 20, 0.9);
    transition: color 200ms ease;
}

.nav-label:hover {
    color: #D97B3D;
    text-decoration: underline;
    text-decoration-color: #D97B3D;
    text-underline-offset: 3px;
}

/* Channel split animation */
@keyframes channelSplit {
    0% {
        text-shadow: none;
        box-shadow: none;
        filter: none;
    }
    25% {
        text-shadow: -6px 0 #C4572A, 6px 0 #3B7EA1, 0 4px #5A9E6F;
        filter: hue-rotate(5deg);
    }
    50% {
        text-shadow: 8px 0 #C4572A, -4px 0 #3B7EA1, 0 -6px #5A9E6F;
        filter: hue-rotate(-5deg);
    }
    75% {
        text-shadow: -4px 0 #C4572A, 4px 0 #3B7EA1, 0 2px #5A9E6F;
        filter: hue-rotate(2deg);
    }
    100% {
        text-shadow: none;
        filter: none;
    }
}

.signal-grid.glitch-active {
    animation: channelSplit 400ms steps(4) forwards;
}

.signal-grid.glitch-active .block:not(.negative-block):not(.chevron-divider):not(.footer-block) {
    box-shadow: -4px 0 0 rgba(196, 87, 42, 0.3),
                4px 0 0 rgba(59, 126, 161, 0.3),
                0 2px 0 rgba(90, 158, 111, 0.2);
}

/* Block focus animation */
@keyframes blockFocus {
    from {
        transform: scale(0.97);
        opacity: 0.85;
    }
    to {
        transform: scale(1.0);
        opacity: 1;
    }
}

/* Scanline drift for subtle ambient motion */
@keyframes scanlineDrift {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 0 4px;
    }
}

body::after {
    animation: scanlineDrift 2s linear infinite;
}

/* Grid gap hairline rules */
.signal-grid {
    background: linear-gradient(
        to right,
        rgba(196, 87, 42, 0.4) 0px,
        rgba(196, 87, 42, 0.4) 1px,
        transparent 1px
    );
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .signal-grid {
        grid-template-columns: repeat(6, 1fr);
        grid-auto-rows: minmax(60px, auto);
    }

    .block[style] {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
    }

    .glyph-container {
        width: 160px;
        height: 160px;
    }

    .display-heading {
        font-size: clamp(28px, 5vw, 48px);
    }

    .nav-chevron {
        bottom: 16px;
        right: 16px;
    }
}
