/* ============================================
   CONCENGINE.COM - Concurrent Event Simulation Engine
   Palette: Chrome-metallic + Dark-neon
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --void: #080c14;
    --surface: #1a1e2e;
    --border: #2a3a5c;
    --primary: #00d4ff;
    --secondary: #00e87b;
    --tertiary: #ffb020;
    --error: #ff2d55;
    --text-primary: #e8edf5;
    --text-secondary: #6b7a8d;
    --glow: #0088cc;

    --font-display: 'Orbitron', sans-serif;
    --font-heading: 'Rajdhani', sans-serif;
    --font-body: 'Exo 2', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--void);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: clamp(0.9rem, 1.4vw, 1.05rem);
    font-weight: 400;
    line-height: 1.7;
    letter-spacing: 0.02em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Grain Overlay --- */
.grain-filter {
    position: absolute;
    width: 0;
    height: 0;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 9999;
    opacity: 0.4;
}

/* --- Scan Lines (hero only) --- */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(0,0,0,0.03) 1px,
        rgba(0,0,0,0.03) 2px
    );
    pointer-events: none;
    z-index: 2;
    animation: scanShift 8s steps(1) infinite;
}

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

/* --- Mini Ring Navigation --- */
#mini-ring-nav {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.3s;
}

#mini-ring-nav:hover {
    opacity: 1;
}

.mini-ring-track {
    fill: none;
    stroke: var(--border);
    stroke-width: 2;
}

.mini-ring-progress {
    fill: none;
    stroke: var(--primary);
    stroke-width: 2;
    stroke-dasharray: 87.96;
    stroke-dashoffset: 87.96;
    transform: rotate(-90deg);
    transform-origin: 32px 32px;
    filter: drop-shadow(0 0 3px var(--glow));
}

/* ============================================
   SCENE 1: HERO
   ============================================ */
#hero {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--void);
    overflow: hidden;
}

.hero-ring-container {
    position: relative;
    width: min(80vw, 800px);
    height: min(80vw, 800px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-ring-svg {
    width: 100%;
    height: 100%;
}

/* HUD Rings */
.hud-ring {
    fill: none;
    stroke: var(--border);
    stroke-width: 1;
    opacity: 0;
}

.ring-outer .hud-ring {
    stroke-dasharray: 8 12;
    stroke-opacity: 0.3;
}

.ring-mid-outer .hud-ring {
    stroke-dasharray: 4 8;
    stroke-opacity: 0.5;
}

.ring-mid-inner .hud-ring {
    stroke-dasharray: 2 6;
    stroke-opacity: 0.7;
}

.ring-inner .hud-ring {
    stroke-dasharray: none;
    stroke-opacity: 0.9;
}

/* Ring draw-in animation states */
.hud-ring.drawing {
    opacity: 1;
    animation: ringDrawIn 1.2s ease-out forwards;
}

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

@keyframes ringDrawIn {
    from {
        stroke-dashoffset: 2262;
        opacity: 0;
    }
    to {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

/* Ring rotation */
.ring-group.rotating {
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.ring-outer.rotating { animation: rotateCW 120s linear infinite; }
.ring-mid-outer.rotating { animation: rotateCCW 80s linear infinite; }
.ring-mid-inner.rotating { animation: rotateCW 50s linear infinite; }
.ring-inner.rotating { animation: rotateCCW 30s linear infinite; }

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

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

.ring-group {
    transform-origin: 400px 400px;
}

/* Ring tick marks */
.ring-tick {
    stroke: var(--primary);
    stroke-width: 1;
    opacity: 0.4;
}

/* Crosshair */
.crosshair {
    opacity: 0;
    transform: scale(0);
    transform-origin: 400px 400px;
}

.crosshair.visible {
    opacity: 1;
    transform: scale(1);
    animation: crosshairSnap 0.15s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
               crosshairPulse 3s ease-in-out infinite 0.15s;
}

@keyframes crosshairSnap {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes crosshairPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Hero arc text */
.hero-arc-text {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    font-weight: 700;
    letter-spacing: 0.35em;
    fill: var(--primary);
    opacity: 0;
    text-transform: uppercase;
}

.hero-arc-text.visible {
    opacity: 1;
    transition: opacity 0.6s ease;
}

/* Hero subtitle */
.hero-subtitle {
    margin-top: 24px;
    text-align: center;
    z-index: 3;
}

.subtitle-text {
    font-family: var(--font-heading);
    font-size: clamp(0.9rem, 1.8vw, 1.2rem);
    font-weight: 600;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.6s ease;
}

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

/* Chevron */
.hero-chevron {
    position: absolute;
    bottom: 40px;
    opacity: 0;
    transition: opacity 0.4s ease;
    animation: chevronBounce 2s ease-in-out infinite;
}

.hero-chevron.visible {
    opacity: 0.6;
}

@keyframes chevronBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

/* ============================================
   SCENE 2: PROCESS PIPELINE
   ============================================ */
#pipeline {
    position: relative;
    width: 100%;
    min-height: 150vh;
    padding: 80px 40px;
}

.pipeline-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    grid-template-rows: auto auto;
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
}

/* Module Blocks */
.module-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateX(-80px);
    transition: opacity 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.module-block[data-direction="right"] {
    transform: translateX(80px);
}

.module-block[data-direction="bottom-left"] {
    transform: translate(-80px, 60px);
}

.module-block[data-direction="bottom-right"] {
    transform: translate(80px, 60px);
}

.module-block.visible {
    opacity: 1;
    transform: translate(0, 0);
}

/* Scheduler block: tall */
.block-scheduler {
    grid-row: span 1;
    min-height: 320px;
}

/* Queue block: wider */
.block-queue {
    min-height: 200px;
}

.block-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(26, 30, 46, 0.8);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-cyan { background: var(--primary); box-shadow: 0 0 6px var(--primary); }
.status-green { background: var(--secondary); box-shadow: 0 0 6px var(--secondary); }
.status-amber { background: var(--tertiary); box-shadow: 0 0 6px var(--tertiary); }
.status-red { background: var(--error); box-shadow: 0 0 6px var(--error); }

.block-label {
    font-family: var(--font-heading);
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.section-label {
    font-family: var(--font-heading);
    font-size: clamp(1rem, 2vw, 1.4rem);
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.block-content {
    padding: 16px;
}

/* Code readout (Scheduler) */
.code-readout {
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 16px;
}

.code-line {
    white-space: pre;
}

.code-line .kw {
    color: var(--primary);
}

.code-line .fn-call {
    color: var(--secondary);
}

.code-line .str {
    color: var(--tertiary);
}

/* Block metrics */
.block-metric {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.metric-label {
    font-family: var(--font-mono);
    font-size: clamp(0.65rem, 0.9vw, 0.75rem);
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: clamp(0.9rem, 1.4vw, 1.1rem);
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.metric-unit {
    font-family: var(--font-mono);
    font-size: clamp(0.6rem, 0.8vw, 0.7rem);
    color: var(--text-secondary);
}

/* Queue visualization */
.queue-visualization {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.queue-slot {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid var(--border);
    transition: background 0.3s;
}

.queue-slot[data-state="active"] {
    background: rgba(0, 212, 255, 0.3);
    border-color: var(--primary);
    box-shadow: 0 0 4px rgba(0, 212, 255, 0.2);
}

.queue-slot[data-state="queued"] {
    background: rgba(255, 176, 32, 0.2);
    border-color: var(--tertiary);
}

.queue-slot[data-state="resolved"] {
    background: rgba(0, 232, 123, 0.2);
    border-color: var(--secondary);
}

/* Resolver visualization */
.resolver-viz {
    margin-bottom: 12px;
}

.resolver-svg {
    width: 100%;
    height: auto;
}

.resolver-label {
    font-family: var(--font-mono);
    font-size: 8px;
    fill: var(--text-secondary);
    text-anchor: middle;
}

/* Mini timeline in block */
.mini-timeline {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 80px;
    margin-bottom: 12px;
}

.tl-bar {
    flex: 1;
    border-radius: 2px 2px 0 0;
    min-width: 8px;
    transition: height 0.6s ease;
}

.tl-bar[data-type="active"] { background: var(--primary); opacity: 0.7; }
.tl-bar[data-type="resolved"] { background: var(--secondary); opacity: 0.6; }
.tl-bar[data-type="queued"] { background: var(--tertiary); opacity: 0.5; }

/* Conduit overlay */
.conduit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.conduit-line {
    fill: none;
    stroke: var(--border);
    stroke-width: 1.5;
    stroke-dasharray: 8 6;
    opacity: 0;
    filter: url(#conduitGlow);
}

.conduit-line.drawing {
    opacity: 1;
    animation: conduitFlow 2s linear infinite;
}

@keyframes conduitFlow {
    from { stroke-dashoffset: 28; }
    to { stroke-dashoffset: 0; }
}

/* Conduit port indicators */
.conduit-port {
    fill: var(--primary);
    opacity: 0;
    transition: opacity 0.3s;
}

.conduit-port.visible {
    opacity: 1;
    animation: portPulse 2s ease-in-out infinite;
}

@keyframes portPulse {
    0%, 100% { r: 3; opacity: 0.8; }
    50% { r: 5; opacity: 1; }
}

/* Event particles */
.event-particle {
    r: 3;
    opacity: 0.8;
}

.event-particle[data-state="active"] { fill: var(--primary); }
.event-particle[data-state="resolved"] { fill: var(--secondary); }
.event-particle[data-state="queued"] { fill: var(--tertiary); }
.event-particle[data-state="failed"] { fill: var(--error); }

/* ============================================
   SCENE 3: TIMELINE
   ============================================ */
#timeline-section {
    position: relative;
    height: 400vh;
}

.timeline-sticky-wrapper {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px;
    overflow: hidden;
}

.timeline-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.timeline-range {
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    color: var(--text-secondary);
    margin-left: auto;
}

.timeline-viewport {
    position: relative;
    width: 100%;
    height: 300px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.timeline-svg {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 4000px;
    transition: transform 0.1s linear;
}

.timeline-fade-left,
.timeline-fade-right {
    position: absolute;
    top: 0;
    width: 80px;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.timeline-fade-left {
    left: 0;
    background: linear-gradient(to right, var(--surface), transparent);
}

.timeline-fade-right {
    right: 0;
    background: linear-gradient(to left, var(--surface), transparent);
}

.timeline-scrub-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.scrub-label {
    font-family: var(--font-mono);
    font-size: clamp(0.6rem, 0.8vw, 0.7rem);
    color: var(--text-secondary);
    letter-spacing: 0.15em;
}

.scrub-progress-bar {
    flex: 1;
    height: 2px;
    background: var(--border);
    border-radius: 1px;
    overflow: hidden;
}

.scrub-progress-fill {
    width: 0%;
    height: 100%;
    background: var(--primary);
    border-radius: 1px;
    transition: width 0.1s linear;
}

/* Timeline event ticks */
.timeline-event-tick {
    stroke-width: 2;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.timeline-event-tick.visible {
    opacity: 0.8;
}

.timeline-event-tick[data-type="active"] { stroke: var(--primary); }
.timeline-event-tick[data-type="resolved"] { stroke: var(--secondary); }
.timeline-event-tick[data-type="queued"] { stroke: var(--tertiary); }
.timeline-event-tick[data-type="failed"] { stroke: var(--error); }

/* Timeline event dots */
.timeline-event-dot {
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
}

.timeline-event-dot.visible {
    opacity: 1;
}

/* ============================================
   SCENE 4: EVENT ANATOMY
   ============================================ */
#event-anatomy {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
}

.anatomy-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
}

.anatomy-container {
    width: min(80vw, 700px);
    height: min(80vw, 700px);
}

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

.anatomy-center-node {
    fill: var(--primary);
    filter: drop-shadow(0 0 8px var(--glow));
    opacity: 0;
    transform: scale(0);
    transform-origin: 400px 400px;
    transition: opacity 0.2s, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.anatomy-center-node.visible {
    opacity: 1;
    transform: scale(1);
}

.anatomy-connector {
    stroke: var(--border);
    stroke-width: 1;
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.5s ease-out;
}

.anatomy-connector.visible {
    stroke-dashoffset: 0;
}

.anatomy-satellite {
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.3s, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.anatomy-satellite.visible {
    opacity: 1;
    transform: scale(1);
}

.anatomy-satellite rect {
    fill: var(--surface);
    stroke: var(--border);
    stroke-width: 1;
}

.sat-label {
    font-family: var(--font-mono);
    font-size: 10px;
    fill: var(--text-secondary);
    text-anchor: middle;
    letter-spacing: 0.1em;
    font-variant: small-caps;
}

.sat-value {
    font-family: var(--font-mono);
    font-size: 11px;
    fill: var(--primary);
    text-anchor: middle;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   SCENE 5: SYSTEM FOOTER
   ============================================ */
#system-footer {
    padding: 32px 40px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.footer-domain {
    font-family: var(--font-display);
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--text-primary);
}

.footer-uptime {
    font-family: var(--font-mono);
    font-size: clamp(0.75rem, 1.1vw, 0.9rem);
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.footer-status-row {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.footer-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: clamp(0.65rem, 0.9vw, 0.75rem);
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

/* ============================================
   PREFERS REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hud-ring { opacity: 1; }
    .crosshair { opacity: 1; transform: scale(1); }
    .hero-arc-text { opacity: 1; }
    .subtitle-text { opacity: 1; }
    .hero-chevron { opacity: 0.6; }
    .module-block { opacity: 1; transform: none; }
    .anatomy-center-node { opacity: 1; transform: scale(1); }
    .anatomy-connector { stroke-dashoffset: 0; }
    .anatomy-satellite { opacity: 1; transform: scale(1); }
}

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

    #pipeline {
        padding: 40px 20px;
    }

    .timeline-sticky-wrapper {
        padding: 20px;
    }

    #event-anatomy {
        padding: 40px 20px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }

    .footer-status-row {
        justify-content: center;
    }
}
