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

:root {
    --cyan: #00e5ff;
    --magenta: #ff2d6f;
    --yellow: #ffe600;
    --bg: #0a0e17;
    --surface: #111827;
    --grid-line: #1a2332;
    --muted: #5a6d80;
    --text: #c8d6e5;
    --error: #ff0844;
    --grid-gap: 2px;
    --noise-intensity: 0.9;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Mono', monospace;
    overflow-x: hidden;
    min-height: 100vh;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
}

/* ===== NOISE OVERLAY ===== */
#noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.04;
    filter: url(#noise);
    background: var(--bg);
    mix-blend-mode: screen;
}

/* ===== SCANLINE INTRO ===== */
#scanline-intro {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--cyan);
    z-index: 2000;
    opacity: 0;
    box-shadow: 0 0 20px var(--cyan), 0 0 60px var(--cyan);
    animation: scanlineIntro 0.8s ease-out 0.3s forwards;
}

@keyframes scanlineIntro {
    0% { top: 0; opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

/* ===== FLOATING DEBRIS ===== */
#floating-debris {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 500;
    overflow: hidden;
}

.debris {
    position: absolute;
    font-family: 'Space Mono', monospace;
    letter-spacing: 0.12em;
    opacity: 0.3;
    pointer-events: none;
    white-space: nowrap;
    will-change: transform;
}

.debris.cyan { color: var(--cyan); }
.debris.magenta { color: var(--magenta); }
.debris.yellow { color: var(--yellow); }
.debris.steel { color: var(--muted); }

/* ===== BENTO GRID ===== */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(80px, auto);
    gap: var(--grid-gap);
    padding: var(--grid-gap);
    min-height: 100vh;
    opacity: 0;
    transform: scale(0.95);
    animation: gridAppear 0.6s ease-out 1.1s forwards;
    background: var(--grid-line);
    transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes gridAppear {
    0% { opacity: 0; transform: scale(0.95); }
    50% { opacity: 1; transform: scale(1); box-shadow: 0 0 20px rgba(0,229,255,0.3); }
    100% { opacity: 1; transform: scale(1); box-shadow: none; }
}

/* ===== BENTO CELLS ===== */
.bento-cell {
    background: var(--surface);
    padding: 16px;
    position: relative;
    overflow: hidden;
    transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Scanline pseudo-element on cells */
.bento-cell::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgba(0,229,255,0.15);
    mix-blend-mode: screen;
    animation: cellScanline var(--scan-duration, 5s) linear infinite;
    animation-delay: var(--scan-delay, 0s);
}

@keyframes cellScanline {
    0% { top: -2px; }
    100% { top: 100%; }
}

/* Cell sizing */
.cell-title {
    grid-column: span 4;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    --scan-duration: 4s;
}

.cell-stat {
    grid-column: span 1;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    --scan-duration: 7s;
}

.cell-map {
    grid-column: span 4;
    grid-row: span 4;
    padding: 8px;
    position: relative;
    --scan-duration: 8s;
}

.cell-readout {
    grid-column: span 2;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    --scan-duration: 6s;
}

.cell-alert {
    grid-column: span 2;
    grid-row: span 2;
    display: flex;
    align-items: center;
    justify-content: center;
    --scan-duration: 3s;
    border: 1px solid transparent;
}

.cell-alert.active {
    border-color: var(--magenta);
    animation: alertPulse 1.5s ease-in-out infinite;
}

@keyframes alertPulse {
    0%, 100% { border-color: var(--magenta); box-shadow: 0 0 10px rgba(255,45,111,0.2); }
    50% { border-color: transparent; box-shadow: none; }
}

.cell-ship {
    grid-column: span 2;
    grid-row: span 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    --scan-duration: 6s;
}

.cell-feed {
    grid-column: span 2;
    grid-row: span 2;
    overflow: hidden;
    --scan-duration: 4s;
}

.cell-plane {
    grid-column: span 1;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    --scan-duration: 5s;
}

.cell-truck {
    grid-column: span 1;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    --scan-duration: 7s;
}

.cell-signal {
    grid-column: span 2;
    grid-row: span 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    --scan-duration: 6s;
}

/* ===== TYPOGRAPHY ===== */
.glitch-text {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(2rem, 5vw, 4.5rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cyan);
    text-shadow: 2px 0 var(--magenta), -2px 0 var(--yellow);
    line-height: 1.1;
    position: relative;
}

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

.glitch-text::before {
    color: var(--magenta);
    clip-path: inset(0 0 70% 0);
    animation: glitchTop 3s infinite linear alternate-reverse;
}

.glitch-text::after {
    color: var(--yellow);
    clip-path: inset(70% 0 0 0);
    animation: glitchBottom 2.5s infinite linear alternate-reverse;
}

@keyframes glitchTop {
    0%, 95% { transform: translate(0); }
    96% { transform: translate(-4px, -2px); }
    97% { transform: translate(2px, 1px); }
    98% { transform: translate(-1px, -3px); }
    99% { transform: translate(3px, 2px); }
    100% { transform: translate(0); }
}

@keyframes glitchBottom {
    0%, 94% { transform: translate(0); }
    95% { transform: translate(3px, 1px); }
    96% { transform: translate(-2px, -2px); }
    97% { transform: translate(4px, 3px); }
    98% { transform: translate(-3px, -1px); }
    100% { transform: translate(0); }
}

.subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    font-weight: 300;
    letter-spacing: 0.02em;
    color: var(--muted);
    margin-top: 8px;
}

.cycle-color {
    animation: cycleTriadic 3s steps(1) infinite;
}

.cycle-color:nth-child(2) { animation-delay: 1s; }
.cycle-color:nth-child(3) { animation-delay: 2s; }

@keyframes cycleTriadic {
    0%, 33% { color: var(--cyan); }
    33.01%, 66% { color: var(--magenta); }
    66.01%, 100% { color: var(--yellow); }
}

/* Stat cells */
.stat-label {
    font-family: 'Space Mono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    color: var(--muted);
    text-transform: uppercase;
}

.stat-value {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.5rem;
    letter-spacing: 0.05em;
}

.stat-value.cyan { color: var(--cyan); }
.stat-value.magenta { color: var(--magenta); }
.stat-value.yellow { color: var(--yellow); }

/* Readout cells */
.readout-label {
    font-family: 'Space Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: var(--magenta);
    text-transform: uppercase;
}

.readout-value {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--text);
    font-weight: 300;
}

/* ===== WORLD MAP ===== */
#world-map, #final-map {
    width: 100%;
    height: 100%;
}

.route {
    stroke-dashoffset: 100;
    animation: routeFlow 4s linear infinite;
}

@keyframes routeFlow {
    0% { stroke-dashoffset: 24; }
    100% { stroke-dashoffset: 0; }
}

.port-active {
    fill: var(--cyan);
    animation: portPulse 2s ease-in-out infinite;
}

.port-disrupted {
    fill: var(--magenta);
    animation: portPulse 1.5s ease-in-out infinite;
}

.port-classified {
    fill: var(--yellow);
    animation: portPulse 2.5s ease-in-out infinite;
}

@keyframes portPulse {
    0%, 100% { r: 4; opacity: 1; }
    50% { r: 6; opacity: 0.6; }
}

.map-overlay-text {
    position: absolute;
    bottom: 12px;
    left: 16px;
}

.map-label {
    font-family: 'Space Mono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    color: var(--muted);
    text-transform: uppercase;
}

.route-label {
    opacity: 0;
    transition: opacity 0.5s;
}

.route-label.visible {
    opacity: 1;
}

/* Route disruption state */
.route-transpacific.disrupted {
    stroke: var(--magenta) !important;
    animation: routeFlow 2s linear infinite, routeGlitch 0.5s ease infinite;
}

@keyframes routeGlitch {
    0%, 90%, 100% { opacity: 1; }
    92% { opacity: 0.3; }
    95% { opacity: 1; }
    97% { opacity: 0.5; }
}

/* ===== ALERT CELL ===== */
.alert-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.alert-icon {
    font-size: 1.5rem;
    color: var(--magenta);
    animation: alertFlash 1s steps(1) infinite;
}

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

.alert-text {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--magenta);
}

.alert-detail {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    color: var(--muted);
    font-weight: 300;
}

/* ===== CONTAINER SHIP CSS ART ===== */
.container-ship {
    position: relative;
    width: 120px;
    height: 60px;
}

.container-ship.small {
    width: 80px;
    height: 40px;
}

.ship-hull {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 40%;
    background: var(--grid-line);
    clip-path: polygon(5% 0%, 95% 0%, 100% 100%, 0% 100%);
    transition: background 0.3s;
}

.ship-bridge {
    position: absolute;
    bottom: 40%;
    right: 10%;
    width: 20%;
    height: 35%;
    background: var(--grid-line);
    transition: background 0.3s;
}

.ship-containers {
    position: absolute;
    bottom: 40%;
    left: 10%;
    width: 65%;
    height: 30%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 1px;
}

.container {
    background: var(--grid-line);
    transition: background 0.3s;
}

.container.c1 { background: rgba(0,229,255,0.3); }
.container.c3 { background: rgba(255,45,111,0.2); }
.container.c5 { background: rgba(255,230,0,0.2); }

.cell-ship:hover .ship-hull,
.cell-ship:hover .ship-bridge {
    background: var(--cyan);
}

.cell-meta {
    font-family: 'Space Mono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    color: var(--muted);
    text-transform: uppercase;
}

.cell-meta-small {
    font-family: 'Space Mono', monospace;
    font-size: 0.55rem;
    letter-spacing: 0.12em;
    color: var(--muted);
    text-transform: uppercase;
}

/* ===== CARGO PLANE CSS ART ===== */
.cargo-plane {
    position: relative;
    width: 50px;
    height: 30px;
}

.plane-body {
    position: absolute;
    top: 40%;
    left: 10%;
    width: 80%;
    height: 25%;
    background: var(--grid-line);
    border-radius: 20px 4px 4px 20px;
}

.plane-wing {
    position: absolute;
    top: 20%;
    left: 30%;
    width: 40%;
    height: 60%;
    background: var(--grid-line);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%);
}

.plane-tail {
    position: absolute;
    top: 10%;
    right: 5%;
    width: 15%;
    height: 50%;
    background: var(--grid-line);
    clip-path: polygon(0% 100%, 50% 0%, 100% 100%);
}

/* ===== CARGO TRUCK CSS ART ===== */
.cargo-truck {
    position: relative;
    width: 50px;
    height: 30px;
}

.truck-body {
    position: absolute;
    top: 20%;
    left: 0;
    width: 65%;
    height: 55%;
    background: var(--grid-line);
}

.truck-cab {
    position: absolute;
    top: 35%;
    right: 0;
    width: 30%;
    height: 40%;
    background: var(--grid-line);
    border-radius: 0 4px 0 0;
}

.truck-wheels {
    position: absolute;
    bottom: 5%;
    left: 10%;
    width: 80%;
    height: 15%;
    background: transparent;
    border-bottom: 3px solid var(--muted);
}

/* ===== DATA FEED ===== */
.data-lines {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    font-weight: 300;
    color: var(--text);
    opacity: 0.8;
    overflow: hidden;
}

.data-line {
    white-space: nowrap;
    animation: fadeInLine 0.3s ease-out;
}

.data-line.highlight {
    color: var(--magenta);
    font-weight: 400;
}

@keyframes fadeInLine {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== SIGNAL BARS ===== */
.signal-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 30px;
}

.bar {
    width: 8px;
    background: var(--cyan);
    animation: barPulse 2s ease-in-out infinite;
}

.bar-1 { height: 30%; animation-delay: 0s; }
.bar-2 { height: 50%; animation-delay: 0.1s; }
.bar-3 { height: 70%; animation-delay: 0.2s; }
.bar-4 { height: 90%; animation-delay: 0.3s; }
.bar-5 { height: 100%; animation-delay: 0.4s; }
.bar-6 { height: 80%; animation-delay: 0.5s; }
.bar-7 { height: 55%; animation-delay: 0.6s; }
.bar-8 { height: 35%; animation-delay: 0.7s; }

@keyframes barPulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 0.3; }
}

/* ===== NARRATIVE SECTION ===== */
#narrative-section {
    padding: 10vh 0;
    position: relative;
}

.narrative-panel {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    position: relative;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    gap: 40px;
}

.narrative-panel.visible {
    opacity: 1;
    transform: translateY(0);
}

.narrative-text {
    max-width: 640px;
}

.narrative-text p {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.875rem, 1.2vw, 1.1rem);
    line-height: 1.7;
    letter-spacing: 0.02em;
    color: var(--text);
    font-weight: 300;
}

.highlight-word {
    background: linear-gradient(transparent 60%, rgba(255,230,0,0.25) 60%);
    padding: 0 2px;
}

.panel-ship-art {
    opacity: 0.3;
    flex-shrink: 0;
}

.panel-ship-art.left { margin-right: 20px; }
.panel-ship-art.right { margin-left: 20px; }

/* ===== FINAL SECTION ===== */
#final-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 40px;
}

#final-map {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 80%;
    opacity: 0.4;
}

.final-routes path {
    animation: routeFlow 3s linear infinite;
}

.final-text {
    position: relative;
    z-index: 10;
    text-align: center;
    opacity: 0;
    transition: opacity 1s ease;
}

.final-text.visible {
    opacity: 1;
}

.final-message {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(1.5rem, 4vw, 3rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--yellow);
    animation: slowBlink 2s ease-in-out infinite;
}

@keyframes slowBlink {
    0%, 40%, 100% { opacity: 1; }
    50%, 60% { opacity: 0.2; }
}

/* ===== RGB CHANNEL SPLIT GLITCH ===== */
.rgb-glitch {
    animation: rgbSplit 0.5s ease-out;
}

@keyframes rgbSplit {
    0% { filter: none; }
    20% { text-shadow: 4px 0 #ff0000, -4px 0 #0000ff; filter: hue-rotate(20deg); }
    40% { text-shadow: -3px 2px #ff0000, 3px -2px #0000ff; filter: hue-rotate(-10deg); }
    60% { text-shadow: 2px -3px #ff0000, -2px 3px #0000ff; }
    80% { text-shadow: -4px 0 #ff0000, 4px 0 #0000ff; filter: hue-rotate(5deg); }
    100% { filter: none; text-shadow: none; }
}

/* ===== GRID PHASE TRANSITIONS ===== */
.bento-grid.phase-disruption {
    background: #1a1020;
}

.bento-grid.phase-disruption .cell-map {
    grid-column: span 8;
}

.bento-grid.phase-collapse {
    grid-template-columns: 1fr;
    gap: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .bento-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .cell-title {
        grid-column: span 4;
    }

    .cell-map {
        grid-column: span 4;
        grid-row: span 3;
    }

    .cell-stat {
        grid-column: span 1;
    }

    .cell-readout {
        grid-column: span 2;
    }

    .cell-alert {
        grid-column: span 2;
    }

    .cell-ship {
        grid-column: span 2;
    }

    .cell-feed {
        grid-column: span 2;
    }

    .cell-signal {
        grid-column: span 2;
    }

    .narrative-panel {
        flex-direction: column;
        padding: 40px 20px;
    }
}
