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

/* ===== CSS VARIABLES ===== */
:root {
    --deep-burgundy: #7B2D3D;
    --warm-cream: #F5E6D0;
    --charcoal-abyss: #0D0D12;
    --charcoal-edge: #1A1520;
    --burnished-gold: #C4A882;
    --crystalline-frost: #A8C8D8;
    --glitch-magenta: #D14B7A;
    --protocol-green: #4AE8A0;
}

/* ===== BASE ===== */
html {
    scroll-behavior: smooth;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.875rem, 1.2vw, 1.1rem);
    line-height: 1.75;
    letter-spacing: 0.02em;
    color: var(--warm-cream);
    background: radial-gradient(ellipse at center, var(--charcoal-abyss) 0%, var(--charcoal-edge) 100%);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ===== SCAN LINES OVERLAY ===== */
#scan-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 3px,
        rgba(168, 200, 216, 0.04) 3px,
        rgba(168, 200, 216, 0.04) 4px
    );
    animation: scanLineShift 3s steps(1) infinite;
}

@keyframes scanLineShift {
    0% { transform: translateY(0); }
    50% { transform: translateY(1px); }
    100% { transform: translateY(0); }
}

/* ===== NOISE OVERLAY ===== */
#noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    opacity: 0.03;
}

/* ===== GLITCH OVERLAY ===== */
#glitch-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 998;
    opacity: 0;
    background: var(--glitch-magenta);
    mix-blend-mode: screen;
    transition: none;
}

#glitch-overlay.active {
    animation: glitchFlash 200ms ease-out forwards;
}

@keyframes glitchFlash {
    0% {
        opacity: 0.15;
        transform: translate(2px, 1px);
    }
    50% {
        opacity: 0.08;
        transform: translate(-1px, 0px);
    }
    100% {
        opacity: 0;
        transform: translate(0, 0);
    }
}

/* ===== PARTICLE FIELD CANVAS ===== */
#particle-field {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* ===== PROTOCOL INDICATOR ===== */
#protocol-indicator {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 500;
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--burnished-gold);
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#protocol-indicator.visible {
    opacity: 1;
}

.protocol-text {
    display: inline-block;
}

.protocol-text::after {
    content: '|';
    animation: protocolBlink 0.8s steps(1) infinite;
    color: var(--protocol-green);
    margin-left: 2px;
}

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

/* ===== HERO SECTION ===== */
#hero {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.hero-content {
    position: relative;
}

.hero-title {
    font-family: 'Space Mono', monospace;
    font-size: clamp(3rem, 10vw, 8rem);
    font-weight: 700;
    color: var(--deep-burgundy);
    letter-spacing: -0.01em;
    line-height: 1.1;
    text-shadow: 1px 1px 0 rgba(245, 230, 208, 0.4);
    position: relative;
    opacity: 0;
}

.hero-title.revealed {
    opacity: 1;
}

/* RGB split glitch for hero title */
.hero-title::before,
.hero-title::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
}

.hero-title.glitch-active::before {
    color: rgba(74, 232, 160, 0.6);
    animation: glitchRed 300ms ease-out forwards;
}

.hero-title.glitch-active::after {
    color: rgba(209, 75, 122, 0.6);
    animation: glitchBlue 300ms ease-out forwards;
}

@keyframes glitchRed {
    0% { opacity: 0.8; transform: translate(-3px, 1px); }
    100% { opacity: 0; transform: translate(0, 0); }
}

@keyframes glitchBlue {
    0% { opacity: 0.8; transform: translate(3px, -1px); }
    100% { opacity: 0; transform: translate(0, 0); }
}

.hero-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    font-weight: 300;
    color: var(--warm-cream);
    opacity: 0;
    margin-top: 1.5rem;
    letter-spacing: 0.04em;
    transition: opacity 1s ease 0.3s;
}

.hero-subtitle.visible {
    opacity: 1;
}

/* ===== CRYSTALLINE DIVIDERS ===== */
.crystalline-divider {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.crystalline-divider.visible {
    opacity: 1;
}

.crystal-facet {
    background: linear-gradient(135deg, rgba(168, 200, 216, 0.15) 0%, transparent 100%);
    transition: clip-path 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    clip-path: polygon(0% 48%, 100% 48%, 100% 52%, 0% 52%);
}

.crystalline-divider.visible .crystal-facet {
    clip-path: var(--facet-shape);
}

.divider-1 .facet-1 { width: 18%; height: 100%; --facet-shape: polygon(0% 30%, 50% 0%, 100% 40%, 80% 100%, 20% 90%); }
.divider-1 .facet-2 { width: 22%; height: 100%; --facet-shape: polygon(10% 0%, 90% 20%, 100% 80%, 60% 100%, 0% 70%); }
.divider-1 .facet-3 { width: 15%; height: 100%; --facet-shape: polygon(20% 10%, 80% 0%, 100% 60%, 50% 100%, 0% 50%); }
.divider-1 .facet-4 { width: 25%; height: 100%; --facet-shape: polygon(0% 20%, 70% 0%, 100% 50%, 80% 100%, 10% 80%); }
.divider-1 .facet-5 { width: 20%; height: 100%; --facet-shape: polygon(30% 0%, 100% 30%, 90% 100%, 0% 80%, 10% 20%); }

.divider-2 .facet-1 { width: 25%; height: 100%; --facet-shape: polygon(0% 40%, 60% 0%, 100% 30%, 70% 100%, 10% 80%); }
.divider-2 .facet-2 { width: 20%; height: 100%; --facet-shape: polygon(15% 0%, 85% 10%, 100% 70%, 50% 100%, 0% 60%); }
.divider-2 .facet-3 { width: 30%; height: 100%; --facet-shape: polygon(5% 20%, 95% 0%, 90% 80%, 60% 100%, 0% 90%); }
.divider-2 .facet-4 { width: 25%; height: 100%; --facet-shape: polygon(20% 0%, 100% 20%, 80% 100%, 40% 90%, 0% 50%); }

.divider-3 .facet-1 { width: 15%; height: 100%; --facet-shape: polygon(10% 0%, 90% 20%, 100% 70%, 40% 100%, 0% 60%); }
.divider-3 .facet-2 { width: 18%; height: 100%; --facet-shape: polygon(0% 30%, 70% 0%, 100% 50%, 80% 100%, 20% 80%); }
.divider-3 .facet-3 { width: 20%; height: 100%; --facet-shape: polygon(5% 10%, 100% 0%, 90% 60%, 50% 100%, 0% 70%); }
.divider-3 .facet-4 { width: 17%; height: 100%; --facet-shape: polygon(20% 0%, 80% 15%, 100% 80%, 60% 100%, 0% 55%); }
.divider-3 .facet-5 { width: 15%; height: 100%; --facet-shape: polygon(0% 20%, 60% 0%, 100% 40%, 70% 100%, 10% 90%); }
.divider-3 .facet-6 { width: 15%; height: 100%; --facet-shape: polygon(30% 0%, 100% 25%, 80% 100%, 0% 75%, 15% 10%); }

.divider-4 .facet-1 { width: 30%; height: 100%; --facet-shape: polygon(0% 35%, 50% 0%, 100% 25%, 85% 100%, 15% 85%); }
.divider-4 .facet-2 { width: 40%; height: 100%; --facet-shape: polygon(10% 0%, 90% 10%, 100% 60%, 60% 100%, 0% 80%); }
.divider-4 .facet-3 { width: 30%; height: 100%; --facet-shape: polygon(20% 0%, 100% 30%, 80% 100%, 40% 90%, 0% 40%); }

.divider-5 .facet-1 { width: 22%; height: 100%; --facet-shape: polygon(0% 20%, 80% 0%, 100% 60%, 50% 100%, 10% 70%); }
.divider-5 .facet-2 { width: 28%; height: 100%; --facet-shape: polygon(10% 0%, 100% 20%, 90% 80%, 40% 100%, 0% 50%); }
.divider-5 .facet-3 { width: 25%; height: 100%; --facet-shape: polygon(5% 10%, 70% 0%, 100% 50%, 80% 100%, 0% 80%); }
.divider-5 .facet-4 { width: 25%; height: 100%; --facet-shape: polygon(20% 0%, 90% 15%, 100% 70%, 60% 100%, 0% 60%); }

/* Rotating crystalline background decorations */
.crystalline-divider::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
    background: linear-gradient(45deg, transparent 40%, rgba(168, 200, 216, 0.03) 50%, transparent 60%);
    animation: crystalRotate 120s linear infinite;
    pointer-events: none;
}

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

/* ===== CONTENT SECTIONS ===== */
.content-section {
    position: relative;
    z-index: 10;
    max-width: 1400px;
    margin: 0 auto;
    padding: 80px 40px;
}

.section-title {
    font-family: 'Space Mono', monospace;
    font-size: clamp(2rem, 4.5vw, 3.8rem);
    font-weight: 700;
    color: var(--deep-burgundy);
    letter-spacing: -0.01em;
    text-shadow: 1px 1px 0 rgba(245, 230, 208, 0.4);
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

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

/* ===== PORTFOLIO GRID ===== */
.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 24px;
}

.grid-cell {
    position: relative;
    background: rgba(13, 13, 18, 0.6);
    border: 1px solid rgba(168, 200, 216, 0.08);
    padding: 32px 28px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease, box-shadow 0.3s ease;
    will-change: transform;
}

.grid-cell.visible {
    opacity: 1;
    transform: translateY(0);
}

.grid-cell:hover {
    box-shadow: 0 0 30px rgba(168, 200, 216, 0.06);
    border-color: rgba(168, 200, 216, 0.15);
}

/* Grid span assignments */
.grid-cell[data-span="3"] { grid-column: span 3; }
.grid-cell[data-span="4"] { grid-column: span 4; }
.grid-cell[data-span="5"] { grid-column: span 5; }
.grid-cell[data-span="6"] { grid-column: span 6; }

/* Every 4th grid item has transmission error offset */
.grid-cell:nth-child(4n) {
    transform: translate(2px, -1px);
}

.grid-cell:nth-child(4n).visible {
    transform: translate(2px, -1px);
}

/* ===== CELL CONTENTS ===== */
.cell-icon {
    width: 56px;
    height: 56px;
    margin-bottom: 20px;
}

.cell-icon svg {
    width: 100%;
    height: 100%;
}

.cell-title {
    font-family: 'Space Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--warm-cream);
    margin-bottom: 12px;
    letter-spacing: 0.01em;
}

.cell-description {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    font-weight: 300;
    color: rgba(245, 230, 208, 0.7);
    line-height: 1.7;
    letter-spacing: 0.02em;
}

/* Animated bottom border */
.cell-border {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--deep-burgundy);
    transition: width 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.grid-cell.visible .cell-border {
    width: 100%;
}

/* ===== CODE INLINE ===== */
.code-inline {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    color: var(--burnished-gold);
}

/* ===== FOOTER ===== */
#site-footer {
    position: relative;
    z-index: 10;
    text-align: center;
    padding: 60px 40px 80px;
}

.footer-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    font-weight: 300;
    color: rgba(245, 230, 208, 0.4);
    letter-spacing: 0.03em;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .portfolio-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    .grid-cell[data-span="3"],
    .grid-cell[data-span="4"],
    .grid-cell[data-span="5"],
    .grid-cell[data-span="6"] {
        grid-column: span 3;
    }
}

@media (max-width: 768px) {
    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    .grid-cell[data-span="3"],
    .grid-cell[data-span="4"],
    .grid-cell[data-span="5"],
    .grid-cell[data-span="6"] {
        grid-column: span 1;
    }
    .content-section {
        padding: 60px 20px;
    }
    .hero-title {
        font-size: clamp(2.5rem, 12vw, 5rem);
    }
    .crystalline-divider {
        height: 50px;
    }
    #protocol-indicator {
        top: 16px;
        left: 16px;
    }
}

@media (max-width: 480px) {
    .portfolio-grid {
        grid-template-columns: 1fr;
    }
    .grid-cell[data-span="3"],
    .grid-cell[data-span="4"],
    .grid-cell[data-span="5"],
    .grid-cell[data-span="6"] {
        grid-column: span 1;
    }
}
