/* ============================================================
   sim-ai.xyz — Experimental Simulation Framework
   Particle physics collision-event aesthetic
   Aurora-gradient palette · Diagonal sectors · Generative tracks
   --
   Typography: Barlow Condensed, Inter, Fira Code (Google Fonts)
   Scroll detection handled in JS via the Intersection Observer API.
   ============================================================ */

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

html {
    scroll-behavior: smooth;
    background: #08040E;
}

body {
    font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
    background: #08040E;
    color: #C8B8E0;
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- Substrate (background layers) ---------- */
.substrate {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background:
        radial-gradient(ellipse at center, rgba(123, 47, 190, 0.08) 0%, rgba(8, 4, 14, 0) 65%),
        #08040E;
}

.polar-grid {
    position: absolute;
    inset: -10%;
    width: 120%;
    height: 120%;
    opacity: 0.55;
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.polar-grid .polar-circle {
    fill: none;
    stroke: #1A0A2E;
    stroke-width: 1;
    opacity: 0.55;
}

.polar-grid .polar-radial {
    stroke: #2A1A3E;
    stroke-width: 0.6;
    opacity: 0.55;
}

.track-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    mix-blend-mode: screen;
}

.detector-rings {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.detector-rings circle {
    fill: none;
    stroke: #2A1A3E;
    stroke-width: 1;
    stroke-dasharray: 4 6;
    opacity: 0.7;
}

.detector-rings .ring-flash {
    fill: #E0B0FF;
    opacity: 0;
}

/* ---------- Energy histogram ---------- */
.energy-histogram {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 5;
    width: 160px;
    padding: 10px 12px 8px;
    background: rgba(26, 10, 46, 0.72);
    border: 1px solid #2A1A3E;
    box-shadow: 0 0 0 1px rgba(123, 47, 190, 0.25) inset;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-family: "Fira Code", monospace;
    color: #7FDBCA;
    user-select: none;
}

.histogram-label {
    font-size: 10px;
    letter-spacing: 0.18em;
    color: #7FDBCA;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.histogram-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 60px;
    width: 100%;
}

.histogram-bars .bar {
    flex: 1 1 4px;
    background: linear-gradient(to top, #7B2FBE 0%, #E0B0FF 60%, #FF4DA6 100%);
    height: 10%;
    transition: height 220ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 0 6px rgba(224, 176, 255, 0.45);
}

.histogram-axis {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #C8B8E0;
    opacity: 0.55;
    margin-top: 4px;
    letter-spacing: 0.08em;
}

/* ---------- Coordinate readout (top-right) ---------- */
.readout {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 5;
    padding: 10px 14px;
    min-width: 180px;
    background: rgba(26, 10, 46, 0.72);
    border: 1px solid #2A1A3E;
    box-shadow: 0 0 0 1px rgba(123, 47, 190, 0.25) inset;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-family: "Fira Code", monospace;
    font-size: 12px;
    color: #7FDBCA;
    user-select: none;
}

.readout-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    line-height: 1.6;
}

.readout-key {
    color: #C8B8E0;
    opacity: 0.7;
    letter-spacing: 0.18em;
}

.readout-val {
    color: #E0B0FF;
}

/* ---------- Top-left brand mark ---------- */
.experience::before {
    content: "SIM-AI · XYZ · CHANNEL 04";
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 5;
    font-family: "Fira Code", monospace;
    font-size: 11px;
    letter-spacing: 0.28em;
    color: #7FDBCA;
    opacity: 0.85;
    padding: 6px 10px;
    border-left: 2px solid #FF4DA6;
    background: rgba(26, 10, 46, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ---------- Main experience container ---------- */
.experience {
    position: relative;
    z-index: 1;
    width: 100%;
}

/* ---------- Scene base ---------- */
.scene {
    position: relative;
    min-height: 100vh;
    width: 100%;
    padding: 96px 6vw;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ---------- Shared text styles ---------- */
.display-title,
.sector-title,
.convergence-title {
    font-family: "Barlow Condensed", "Inter", sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #E0B0FF;
    text-shadow: 2px 2px 0 #7B2FBE;
    line-height: 0.95;
}

.annotation {
    font-family: "Fira Code", monospace;
    font-size: 14px;
    color: #7FDBCA;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.annotation-dim {
    color: #C8B8E0;
    opacity: 0.55;
    font-size: 12px;
    margin-top: 6px;
}

.panel-tag {
    display: inline-block;
    font-family: "Fira Code", monospace;
    font-size: 11px;
    letter-spacing: 0.28em;
    color: #7FDBCA;
    text-transform: uppercase;
    padding: 4px 10px;
    border: 1px solid #2A1A3E;
    border-left: 2px solid #7B2FBE;
    background: rgba(26, 10, 46, 0.6);
}

.panel-tag-accent {
    border-left-color: #E0B0FF;
    color: #E0B0FF;
}

.panel-tag-magenta {
    border-left-color: #FF4DA6;
    color: #FF4DA6;
}

.panel-body {
    font-family: "Inter", sans-serif;
    font-size: 17px;
    line-height: 1.7;
    color: #C8B8E0;
    max-width: 55ch;
}

.panel-body em {
    font-style: normal;
    color: #E0B0FF;
    background: linear-gradient(180deg, transparent 60%, rgba(255, 77, 166, 0.18) 60%);
    padding: 0 2px;
}

.panel-body-mono {
    font-family: "Fira Code", monospace;
    font-size: 12px;
    color: #7FDBCA;
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    letter-spacing: 0.12em;
}

.kv {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

.kv span:first-child {
    color: #C8B8E0;
    opacity: 0.6;
    font-size: 10px;
    letter-spacing: 0.22em;
}

.kv-val {
    color: #E0B0FF;
    font-size: 14px;
}

/* ============================================================
   SCENE 1 — GENESIS
   ============================================================ */
.scene-genesis {
    flex-direction: column;
    text-align: center;
}

.genesis-vertex {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #FFFFFF;
    transform: translate(-50%, -50%);
    box-shadow:
        0 0 18px 4px #E0B0FF,
        0 0 60px 20px rgba(224, 176, 255, 0.35),
        0 0 140px 40px rgba(123, 47, 190, 0.25);
    animation: vertex-pulse 3.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
    z-index: 2;
}

@keyframes vertex-pulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow:
            0 0 18px 4px #E0B0FF,
            0 0 60px 20px rgba(224, 176, 255, 0.35),
            0 0 140px 40px rgba(123, 47, 190, 0.25);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.4);
        box-shadow:
            0 0 28px 8px #FF4DA6,
            0 0 90px 28px rgba(255, 77, 166, 0.45),
            0 0 220px 60px rgba(123, 47, 190, 0.35);
    }
}

.genesis-text {
    position: relative;
    z-index: 3;
    margin-top: 22vh;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.genesis-text.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.genesis-text .display-title {
    font-size: clamp(48px, 9vw, 96px);
    letter-spacing: 0.12em;
    margin-bottom: 14px;
}

.genesis-text .annotation {
    margin-top: 4px;
}

.scroll-cue {
    position: absolute;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%);
    font-family: "Fira Code", monospace;
    font-size: 10px;
    letter-spacing: 0.32em;
    color: #7FDBCA;
    text-transform: uppercase;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0.7;
    animation: scroll-cue 2.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
}

.scroll-cue-arrow {
    font-size: 14px;
    color: #E0B0FF;
}

@keyframes scroll-cue {
    0%, 100% { transform: translate(-50%, 0); opacity: 0.7; }
    50% { transform: translate(-50%, 6px); opacity: 1; }
}

/* ============================================================
   SCENE 2 — DIVERGENCE
   ============================================================ */
.scene-divergence {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6vw;
    align-items: center;
}

.diverge-tracks {
    position: relative;
    height: 60vh;
    min-height: 420px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.branch-diagram {
    width: 100%;
    max-width: 520px;
    height: auto;
    overflow: visible;
}

.branch-diagram .branch-origin {
    fill: #E0B0FF;
    filter: drop-shadow(0 0 10px #FF4DA6);
}

.branch-diagram .branch-path {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
}

.branch-trunk { stroke: #E0B0FF; }
.branch-up { stroke: #FF4DA6; }
.branch-mid { stroke: #7FDBCA; }
.branch-down { stroke: #C8B8E0; }

.scene-divergence.is-visible .branch-trunk {
    animation: branch-draw 1.1s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}
.scene-divergence.is-visible .branch-up {
    animation: branch-draw 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.7s forwards;
}
.scene-divergence.is-visible .branch-mid {
    animation: branch-draw 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.95s forwards;
}
.scene-divergence.is-visible .branch-down {
    animation: branch-draw 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 1.2s forwards;
}

@keyframes branch-draw {
    to { stroke-dashoffset: 0; }
}

.branch-diagram .branch-tip {
    opacity: 0;
}

.branch-diagram .branch-tip-1 { fill: #FF4DA6; }
.branch-diagram .branch-tip-2 { fill: #7FDBCA; }
.branch-diagram .branch-tip-3 { fill: #C8B8E0; }

.scene-divergence.is-visible .branch-tip-1 {
    animation: tip-pop 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2.05s forwards;
}
.scene-divergence.is-visible .branch-tip-2 {
    animation: tip-pop 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2.3s forwards;
}
.scene-divergence.is-visible .branch-tip-3 {
    animation: tip-pop 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2.55s forwards;
}

@keyframes tip-pop {
    0% { opacity: 0; transform: scale(0); transform-origin: center; }
    60% { opacity: 1; transform: scale(1.6); }
    100% { opacity: 1; transform: scale(1); }
}

.branch-label {
    fill: #7FDBCA;
    letter-spacing: 0.18em;
    opacity: 0;
}

.scene-divergence.is-visible .branch-label {
    animation: label-fade 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2.4s forwards;
}

@keyframes label-fade {
    to { opacity: 0.85; }
}

.diverge-panel {
    position: relative;
    padding: 56px 56px 56px 64px;
    background: linear-gradient(135deg, rgba(26, 10, 46, 0.96) 0%, rgba(42, 26, 62, 0.78) 100%);
    border: 1px solid #2A1A3E;
    box-shadow:
        0 0 0 1px rgba(123, 47, 190, 0.25) inset,
        0 30px 80px -20px rgba(123, 47, 190, 0.35);
    /* Trapezoidal sector */
    clip-path: polygon(6% 0, 100% 4%, 96% 100%, 0 96%);
    transform: rotate(-1.5deg);
    opacity: 0;
    transition: opacity 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.diverge-panel::before {
    content: "";
    position: absolute;
    left: 18px;
    top: 18px;
    bottom: 18px;
    width: 2px;
    background: linear-gradient(180deg, #FF4DA6, #7B2FBE 50%, #7FDBCA);
    opacity: 0.85;
}

.scene-divergence.is-visible .diverge-panel {
    opacity: 1;
    transform: rotate(-1.5deg) translateX(0);
}

.diverge-panel .panel-header {
    display: flex;
    gap: 12px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.sector-title {
    font-size: clamp(48px, 6vw, 84px);
    margin-bottom: 24px;
}

/* ============================================================
   SCENE 3 — MULTIVERSE
   ============================================================ */
.scene-multiverse {
    flex-direction: column;
    align-items: stretch;
    gap: 36px;
}

.multiverse-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.multiverse-header .sector-title {
    font-size: clamp(40px, 5.5vw, 72px);
    margin: 4px 0 8px;
}

.multiverse-sub {
    font-family: "Fira Code", monospace;
    color: #C8B8E0;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 12px;
    opacity: 0.85;
}

.multiverse-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 14px;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    aspect-ratio: 16 / 11;
}

.quadrant {
    position: relative;
    border: 1px solid #7B2FBE;
    background: linear-gradient(180deg, rgba(8, 4, 14, 0.9), rgba(26, 10, 46, 0.95));
    overflow: hidden;
    transition: transform 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform: scale(1);
}

.scene-multiverse.is-visible .quadrant {
    box-shadow: 0 0 0 1px rgba(123, 47, 190, 0.4) inset,
                0 20px 40px -20px rgba(123, 47, 190, 0.6);
}

.scene-multiverse.is-visible #quadrantA { animation: quad-ripple 2.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.0s infinite; }
.scene-multiverse.is-visible #quadrantB { animation: quad-ripple 2.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.3s infinite; }
.scene-multiverse.is-visible #quadrantC { animation: quad-ripple 2.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.6s infinite; }
.scene-multiverse.is-visible #quadrantD { animation: quad-ripple 2.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.9s infinite; }

@keyframes quad-ripple {
    0%, 100% { transform: scale(1); }
    40% { transform: scale(1.02); }
}

.quadrant-head {
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    font-family: "Fira Code", monospace;
    font-size: 11px;
    letter-spacing: 0.22em;
    pointer-events: none;
}

.quadrant-label {
    color: #E0B0FF;
    text-transform: uppercase;
    text-shadow: 0 0 8px rgba(224, 176, 255, 0.6);
}

.quadrant-meta {
    color: #7FDBCA;
    opacity: 0.85;
}

.quadrant-foot {
    position: absolute;
    bottom: 10px;
    left: 12px;
    right: 12px;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    font-family: "Fira Code", monospace;
    font-size: 10px;
    letter-spacing: 0.24em;
    color: #C8B8E0;
    opacity: 0.65;
    pointer-events: none;
}

.quadrant-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    mix-blend-mode: screen;
}

/* ============================================================
   SCENE 4 — CONVERGENCE
   ============================================================ */
.scene-convergence {
    flex-direction: column;
    padding: 96px 6vw;
}

.convergence-stage {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.convergence-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    mix-blend-mode: screen;
    opacity: 0.85;
}

.convergence-text {
    position: relative;
    z-index: 2;
    text-align: center;
    max-width: 720px;
    padding: 48px 32px;
    background: radial-gradient(ellipse at center, rgba(8, 4, 14, 0.78) 0%, rgba(8, 4, 14, 0.1) 80%);
}

.convergence-title {
    font-size: clamp(40px, 5vw, 64px);
    margin: 18px 0 12px;
    position: relative;
    display: inline-block;
    color: #E0B0FF;
    line-height: 1.05;
}

.convergence-emph {
    color: #FF4DA6;
    text-shadow: 2px 2px 0 #7B2FBE, 0 0 22px rgba(255, 77, 166, 0.55);
    display: block;
}

.convergence-underline {
    position: absolute;
    left: 0;
    bottom: -10px;
    height: 2px;
    width: 0;
    background: linear-gradient(90deg, #FF4DA6, #E0B0FF);
    transition: width 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.scene-convergence.is-visible .convergence-underline {
    width: 100%;
}

.convergence-body {
    margin: 0 auto 24px;
    color: #C8B8E0;
}

.convergence-meta {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 36px;
    font-family: "Fira Code", monospace;
}

.convergence-meta .kv {
    align-items: center;
}

/* ============================================================
   SCENE 5 — TERMINUS
   ============================================================ */
.scene-terminus {
    flex-direction: column;
    text-align: center;
}

.terminus-frame {
    position: relative;
    max-width: 720px;
    padding: 64px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.terminus-prelude {
    font-family: "Fira Code", monospace;
    font-size: 11px;
    letter-spacing: 0.42em;
    color: #FF4DA6;
    text-transform: uppercase;
}

.terminus-statement {
    font-family: "Inter", sans-serif;
    font-size: 18px;
    line-height: 1.7;
    color: #F0E8F8;
    max-width: 50ch;
}

.terminus-statement-dim {
    color: #C8B8E0;
    opacity: 0.7;
    font-size: 16px;
}

.terminus-domain {
    font-family: "Barlow Condensed", "Inter", sans-serif;
    font-weight: 700;
    font-size: 36px;
    color: #7FDBCA;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-top: 12px;
    text-shadow: 0 0 18px rgba(127, 219, 202, 0.45), 2px 2px 0 #7B2FBE;
    animation: terminus-pulse 3s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
}

@keyframes terminus-pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.terminus-tag {
    font-family: "Fira Code", monospace;
    font-size: 11px;
    letter-spacing: 0.32em;
    color: #C8B8E0;
    opacity: 0.6;
}

.terminus-vertex {
    position: relative;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #E0B0FF;
    box-shadow: 0 0 14px 4px rgba(224, 176, 255, 0.65);
    margin-top: 16px;
    opacity: 0.8;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
    .scene {
        padding: 80px 5vw;
    }

    .scene-divergence {
        grid-template-columns: 1fr;
        gap: 40px;
    }

    .diverge-panel {
        padding: 40px 28px 40px 36px;
        transform: rotate(-1deg);
    }

    .scene-divergence.is-visible .diverge-panel {
        transform: rotate(-1deg) translateX(0);
    }

    .multiverse-grid {
        aspect-ratio: 4 / 5;
    }

    .energy-histogram {
        width: 132px;
        right: 12px;
        bottom: 12px;
    }

    .readout {
        right: 12px;
        top: 12px;
        min-width: 150px;
        font-size: 11px;
    }

    .experience::before {
        font-size: 10px;
        letter-spacing: 0.22em;
        top: 12px;
        left: 12px;
    }
}

@media (max-width: 600px) {
    .multiverse-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, 1fr);
        aspect-ratio: 3 / 5;
    }

    .panel-body-mono {
        gap: 16px;
    }

    .convergence-meta {
        gap: 20px;
    }
}
