/* ===========================
   CSS Custom Properties
   =========================== */
:root {
    --void-black: #06090f;
    --abyss-navy: #0c1829;
    --cyan: #4aeadc;
    --amber: #f0a830;
    --green: #22e87a;
    --crimson: #e84057;
    --ghost-slate: #3a4a5e;
    --ice: #b8c6d4;

    --font-display: 'Orbitron', sans-serif;
    --font-body: 'Exo 2', sans-serif;
    --font-mono: 'Fira Code', monospace;

    --radar-duration: 8s;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--void-black);
    color: var(--ice);
    font-family: var(--font-body);
    font-size: clamp(0.95rem, 1.6vw, 1.15rem);
    line-height: 1.75;
    overflow-x: hidden;
    overflow-y: auto;
}

/* ===========================
   Scanline Overlay
   =========================== */
#scanline-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        rgba(74, 234, 220, 0.015) 0px,
        rgba(74, 234, 220, 0.015) 1px,
        transparent 1px,
        transparent 3px
    );
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#scanline-overlay.visible {
    opacity: 1;
}

/* ===========================
   Radar Sweep
   =========================== */
#radar-sweep {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#radar-sweep.visible {
    opacity: 1;
}

#radar-sweep::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        transparent 340deg,
        rgba(74, 234, 220, 0.04) 360deg
    );
    animation: radarSweep var(--radar-duration) linear infinite;
}

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

/* ===========================
   Grid Lines (quadrant dividers)
   =========================== */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 50%;
    width: 1px;
    height: 100%;
    background: rgba(74, 234, 220, 0.12);
    z-index: 1;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    background: rgba(74, 234, 220, 0.12);
    z-index: 1;
    pointer-events: none;
}

/* ===========================
   HUD Corner Brackets
   =========================== */
.hud-bracket {
    position: fixed;
    z-index: 100;
    animation: bracketPulse 4s ease-in-out infinite;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.hud-bracket.visible {
    opacity: 1;
}

.hud-bracket.dimmed {
    opacity: 0.4;
}

.hud-bracket svg {
    display: block;
}

.hud-bracket svg path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.4s ease;
}

.hud-bracket.visible svg path {
    stroke-dashoffset: 0;
}

.hud-bracket--tl {
    top: 16px;
    left: 16px;
}

.hud-bracket--tr {
    top: 16px;
    right: 16px;
    text-align: right;
}

.hud-bracket--bl {
    bottom: 16px;
    left: 16px;
}

.hud-bracket--br {
    bottom: 16px;
    right: 16px;
    text-align: right;
}

.hud-metric {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--cyan);
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.hud-metric::after {
    content: attr(data-label);
    display: block;
    font-size: 9px;
    color: var(--ghost-slate);
    letter-spacing: 0.1em;
}

@keyframes bracketPulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(0.6); }
}

/* ===========================
   Section Navigation
   =========================== */
#section-nav {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.nav-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid var(--cyan);
    background: transparent;
    cursor: pointer;
    padding: 0;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.nav-dot.active {
    background: var(--cyan);
    box-shadow: 0 0 8px rgba(74, 234, 220, 0.5);
}

.nav-dot:hover {
    box-shadow: 0 0 12px rgba(74, 234, 220, 0.6);
}

/* ===========================
   Scroll Spacer
   =========================== */
#scroll-spacer {
    height: 600vh;
    pointer-events: none;
}

/* ===========================
   Viewport / Scene Container
   =========================== */
#viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
    overflow: hidden;
}

.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.8s ease;
    pointer-events: none;
}

.scene.active {
    opacity: 1;
    pointer-events: auto;
}

/* ===========================
   Scene 1: Telemetry Splash
   =========================== */
#wireframe-sphere {
    position: absolute;
    width: min(70vw, 70vh);
    height: min(70vw, 70vh);
    opacity: 0;
    transition: opacity 0.8s ease;
}

#wireframe-sphere.visible {
    opacity: 1;
}

#wireframe-sphere svg {
    width: 100%;
    height: 100%;
    animation: sphereRotate 90s linear infinite;
}

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

#title-container {
    position: relative;
    z-index: 5;
    text-align: center;
}

#main-title {
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 5vw, 5rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--cyan);
    text-shadow: 0 0 20px rgba(74, 234, 220, 0.3);
    min-height: 1.2em;
}

#main-title .char {
    display: inline-block;
    opacity: 0;
    text-shadow: 0 0 40px rgba(74, 234, 220, 0.8);
    transition: text-shadow 0.3s ease;
}

#main-title .char.revealed {
    opacity: 1;
}

#main-title .char.steady {
    text-shadow: 0 0 20px rgba(74, 234, 220, 0.3);
}

#subtitle {
    font-family: var(--font-body);
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    color: var(--ghost-slate);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-top: 1rem;
    opacity: 0;
    transition: opacity 0.6s ease 0.3s;
}

#subtitle.visible {
    opacity: 1;
}

/* ===========================
   Scene 2: Event Topology
   =========================== */
#scene-topology {
    justify-content: flex-start;
}

#network-graph {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

#network-graph svg {
    width: 100%;
    height: 100%;
}

.graph-edge {
    stroke: var(--ghost-slate);
    stroke-width: 1;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.graph-edge.active {
    stroke: var(--cyan);
    opacity: 0.8;
    stroke-dasharray: 200;
    animation: edgePulse 0.6s ease forwards;
}

@keyframes edgePulse {
    from { stroke-dashoffset: 200; }
    to { stroke-dashoffset: 0; }
}

.graph-node {
    fill: none;
    stroke: var(--ghost-slate);
    stroke-width: 1.5;
    transition: fill 0.3s ease, stroke 0.3s ease;
}

.graph-node.active {
    fill: var(--cyan);
    stroke: var(--cyan);
    filter: drop-shadow(0 0 8px rgba(74, 234, 220, 0.6));
}

.graph-node-label {
    fill: var(--ice);
    font-family: var(--font-mono);
    font-size: 10px;
    text-anchor: middle;
    letter-spacing: 0.05em;
    opacity: 0.6;
}

#topology-sidebar {
    position: absolute;
    right: 0;
    top: 0;
    width: 320px;
    height: 100%;
    background: rgba(12, 24, 41, 0.85);
    border-left: 1px solid rgba(74, 234, 220, 0.3);
    padding: 80px 24px 24px;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
}

#scene-topology.active #topology-sidebar {
    transform: translateX(0);
}

#topology-sidebar h2 {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--cyan);
    text-shadow: 0 0 20px rgba(74, 234, 220, 0.3);
    margin-bottom: 2rem;
}

.sidebar-block {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(74, 234, 220, 0.15);
}

.sidebar-block:last-child {
    border-bottom: none;
}

.sidebar-block h3 {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--amber);
    margin-bottom: 0.75rem;
}

.sidebar-block p {
    color: var(--ice);
    max-width: 64ch;
}

/* ===========================
   Scene 3: Concurrency Visualizer
   =========================== */
#scene-concurrency {
    flex-direction: column;
    justify-content: center;
}

#event-streams {
    width: 100%;
    padding: 0 80px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.stream-lane {
    position: relative;
    height: 28px;
    border-top: 1px solid rgba(74, 234, 220, 0.1);
    border-bottom: 1px solid rgba(74, 234, 220, 0.1);
    overflow: hidden;
}

.event-packet {
    position: absolute;
    width: 28px;
    height: 12px;
    border-radius: 3px;
    top: 50%;
    transform: translateY(-50%);
    left: -30px;
    animation: packetFlow var(--packet-duration, 3s) linear forwards;
}

.event-packet.scheduled {
    background: var(--cyan);
    box-shadow: 0 0 6px rgba(74, 234, 220, 0.4);
}

.event-packet.contending {
    background: var(--amber);
    box-shadow: 0 0 6px rgba(240, 168, 48, 0.4);
}

.event-packet.resolved {
    background: var(--green);
    box-shadow: 0 0 6px rgba(34, 232, 122, 0.4);
}

.event-packet.deadlocked {
    background: var(--crimson);
    box-shadow: 0 0 6px rgba(232, 64, 87, 0.4);
}

@keyframes packetFlow {
    from { left: -30px; }
    to { left: calc(100% + 30px); }
}

.collision-flash {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: white;
    top: 50%;
    transform: translate(-50%, -50%);
    animation: collisionBurst 0.2s ease-out forwards;
}

@keyframes collisionBurst {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8); opacity: 1; }
    100% { box-shadow: 0 0 20px 10px rgba(255, 255, 255, 0); opacity: 0; }
}

#timeline-ruler {
    width: calc(100% - 160px);
    margin: 30px 80px 0;
    height: 2px;
    background: rgba(74, 234, 220, 0.15);
    position: relative;
}

#timeline-fill {
    height: 100%;
    background: var(--cyan);
    width: 0;
    transition: width 4s linear;
}

#timeline-markers {
    position: relative;
    height: 20px;
}

.timeline-mark {
    position: absolute;
    top: 4px;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--ghost-slate);
    transform: translateX(-50%);
}

#stream-label {
    position: absolute;
    top: 60px;
    left: 80px;
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--cyan);
    text-shadow: 0 0 20px rgba(74, 234, 220, 0.3);
}

#pause-hint {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--ghost-slate);
    letter-spacing: 0.1em;
    opacity: 0.5;
}

#scene-concurrency.paused .event-packet {
    animation-play-state: paused;
}

#scene-concurrency.paused #pause-hint {
    color: var(--amber);
    opacity: 1;
}

/* ===========================
   Scene 4: Architecture Deep-Dive
   =========================== */
#scene-deepdive {
    overflow-y: auto;
    align-items: flex-start;
    justify-content: center;
    pointer-events: auto;
}

#deepdive-column {
    max-width: 640px;
    width: 90%;
    margin: 0 auto;
    padding: 80px 0 120px;
}

.deepdive-block {
    margin-bottom: clamp(2rem, 4vw, 4rem);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.deepdive-block.visible {
    opacity: 1;
    transform: translateY(0);
}

.deepdive-block h2 {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--cyan);
    text-shadow: 0 0 20px rgba(74, 234, 220, 0.3);
    margin-bottom: 1.2rem;
}

.deepdive-block p {
    color: var(--ice);
    max-width: 64ch;
    margin-bottom: 1.5rem;
}

.code-block {
    position: relative;
    background: var(--abyss-navy);
    border: 1px solid rgba(74, 234, 220, 0.3);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 1rem;
}

.code-block .code-border {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 1px solid var(--cyan);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.code-block.active .code-border {
    opacity: 0.5;
}

.code-block pre {
    padding: 1.5rem;
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    color: var(--cyan);
    letter-spacing: 0.05em;
    line-height: 1.8;
    overflow-x: auto;
}

.code-block pre code .code-line {
    display: block;
    opacity: 0;
    transition: opacity 0.06s ease;
}

.code-block pre code .code-line.visible {
    opacity: 1;
}

/* ===========================
   Scene 5: Signal Terminus
   =========================== */
#scene-terminus {
    flex-direction: column;
}

#terminus-layers {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#terminus-sphere {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.3;
}

#terminus-sphere svg {
    width: 100%;
    height: 100%;
}

#terminus-graph {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.2;
}

#terminus-streams {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.15;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 30px;
    padding: 0 80px;
}

.terminus-lane {
    height: 2px;
    background: linear-gradient(to right,
        transparent,
        var(--cyan) 20%,
        var(--amber) 40%,
        var(--green) 60%,
        var(--crimson) 80%,
        transparent
    );
    opacity: 0.4;
}

#terminus-center {
    position: relative;
    z-index: 5;
    text-align: center;
}

#tagline {
    font-family: var(--font-body);
    font-style: italic;
    font-weight: 300;
    font-size: 1.8rem;
    letter-spacing: 0.15em;
    color: var(--ice);
    opacity: 0;
    transition: opacity 0.8s ease;
}

#scene-terminus.active #tagline {
    opacity: 1;
}

#contact-email {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    color: var(--cyan);
    text-decoration: none;
    letter-spacing: 0.05em;
    margin-top: 2rem;
    position: relative;
    padding-bottom: 4px;
}

#contact-email::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--cyan);
    transition: width 0.4s ease;
}

#scene-terminus.active #contact-email::after {
    width: 100%;
}

#contact-email:hover {
    color: var(--amber);
}

#contact-email:hover::after {
    background: var(--amber);
}

/* ===========================
   Responsive: Mobile
   =========================== */
@media (max-width: 768px) {
    #topology-sidebar {
        width: 100%;
        height: 60vh;
        top: auto;
        bottom: 0;
        right: 0;
        border-left: none;
        border-top: 1px solid rgba(74, 234, 220, 0.3);
        transform: translateY(100%);
        padding: 24px;
    }

    #scene-topology.active #topology-sidebar {
        transform: translateY(0);
    }

    #event-streams {
        padding: 0 40px;
    }

    #timeline-ruler {
        width: calc(100% - 80px);
        margin-left: 40px;
        margin-right: 40px;
    }

    #stream-label {
        left: 40px;
    }

    .hud-bracket--tl,
    .hud-bracket--tr,
    .hud-bracket--bl,
    .hud-bracket--br {
        transform: scale(0.75);
    }

    #section-nav {
        right: 12px;
    }

    #terminus-streams {
        padding: 0 40px;
    }
}

/* ===========================
   Utility
   =========================== */
.orbitron {
    font-family: var(--font-display);
}

.exo2 {
    font-family: var(--font-body);
}

.fira {
    font-family: var(--font-mono);
}

/* Prevent text selection on HUD elements */
.hud-bracket,
.nav-dot,
#stream-label,
#pause-hint {
    user-select: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: var(--void-black);
}

::-webkit-scrollbar-thumb {
    background: var(--ghost-slate);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--cyan);
}
