/* === BRAIN-PIPELINE.CSS ===
 * brain.ai-platform.space wow визуал hero
 * Анимация: источники - база - мозг - Bloomberg ответ
 * Чистый CSS + vanilla JS, БЕЗ библиотек, 60fps
 */

/* === Контейнер === */
.brain-pipeline {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 560px;
    display: grid;
    grid-template-areas:
        "sources core"
        "answer  answer";
    grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr);
    grid-template-rows: minmax(280px, auto) minmax(220px, 1fr);
    gap: 18px;
    align-items: stretch;
    padding: 20px;
    isolation: isolate;
    background:
        radial-gradient(ellipse at 30% 30%, rgba(255, 215, 0, 0.06) 0%, transparent 55%),
        radial-gradient(ellipse at 70% 70%, rgba(0, 240, 255, 0.06) 0%, transparent 55%),
        linear-gradient(135deg, rgba(20, 20, 20, 0.6), rgba(10, 10, 10, 0.4));
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.4),
        inset 0 0 80px rgba(0, 240, 255, 0.03);
}

/* Соединительная стрелка из core ВНИЗ к answer (визуальный flow) */
.brain-pipeline::before {
    content: "";
    position: absolute;
    left: 50%;
    top: calc(50% - 12px);
    width: 1px;
    height: 24px;
    background: linear-gradient(180deg, transparent, var(--gold), var(--electric));
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 1;
    opacity: 0.6;
}
.brain-pipeline::after {
    content: "▼";
    position: absolute;
    left: 50%;
    top: calc(50% + 4px);
    transform: translateX(-50%);
    color: var(--electric);
    font-size: 10px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.7;
    text-shadow: 0 0 8px var(--electric-dim);
    animation: bp-arrow-pulse 2s ease-in-out infinite;
}
@keyframes bp-arrow-pulse {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.5; }
    50%      { transform: translateX(-50%) translateY(3px); opacity: 1; }
}

/* === ИСТОЧНИКИ - вертикальный столбец слева === */
.bp-sources {
    grid-area: sources;
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(38px, auto);
    gap: 8px;
    z-index: 2;
    align-content: center;
}

.bp-source {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    padding: 0 10px;
    height: 36px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 18px;
    font-size: 11px;
    color: var(--text-secondary);
    backdrop-filter: blur(8px);
    transition: all 0.3s var(--ease-out-quart);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.bp-source::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, var(--gold-dim) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.bp-source.is-pulsing::before {
    animation: bp-source-pulse 0.8s ease-out;
}

@keyframes bp-source-pulse {
    0%, 100% { opacity: 0; transform: scale(1); }
    50%      { opacity: 1; transform: scale(1.06); }
}

.bp-source.is-pulsing {
    border-color: var(--gold);
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.35);
}

.bp-source-icon {
    font-size: 14px;
    flex-shrink: 0;
    line-height: 1;
}

.bp-source-label {
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: 0.3px;
    font-size: 10.5px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === ЦЕНТР: база + мозг (вертикально, рядом с sources) === */
.bp-core {
    grid-area: core;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;
    z-index: 2;
    position: relative;
}

/* === БАЗА ДАННЫХ - WOW-вариант: стек + орбиты + точки данных === */
.bp-database {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    position: relative;
}

.bp-database::after {
    content: "";
    position: absolute;
    width: 200px;
    height: 200px;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(0, 240, 255, 0.22) 0%, transparent 60%);
    pointer-events: none;
    animation: bp-db-glow 3s ease-in-out infinite;
    z-index: -1;
}

@keyframes bp-db-glow {
    0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(0.95); }
    50%      { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

/* Контейнер */
.bp-db-stack {
    position: relative;
    width: 110px;
    height: 110px;
}

/* Орбитальные кольца (3 шт, разные радиусы и скорости) */
.bp-db-orbit {
    position: absolute;
    top: 50%; left: 50%;
    border: 1px dashed rgba(0, 240, 255, 0.35);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}
.bp-db-orbit-1 {
    width: 110px; height: 110px;
    animation: bp-orbit-rotate 12s linear infinite;
    border-color: rgba(255, 215, 0, 0.3);
}
.bp-db-orbit-2 {
    width: 86px; height: 86px;
    animation: bp-orbit-rotate 8s linear infinite reverse;
    border-color: rgba(0, 240, 255, 0.4);
    border-style: dotted;
}
.bp-db-orbit-3 {
    width: 60px; height: 60px;
    animation: bp-orbit-rotate 5s linear infinite;
    border-color: rgba(255, 215, 0, 0.5);
    border-style: dashed;
}

@keyframes bp-orbit-rotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to   { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Стек слоев базы (сегменты данных) */
.bp-db-layer {
    position: absolute;
    left: 50%;
    width: 56px;
    height: 9px;
    border-radius: 50%;
    transform: translateX(-50%);
    background:
        linear-gradient(180deg,
            rgba(0, 240, 255, 0.95) 0%,
            rgba(59, 130, 246, 0.7) 100%);
    box-shadow:
        0 0 12px rgba(0, 240, 255, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(0, 240, 255, 0.6);
    z-index: 2;
}
.bp-db-layer-1 { top: 28px; opacity: 0.85; animation: bp-layer-pulse 2.4s ease-in-out infinite 0s; }
.bp-db-layer-2 { top: 42px; opacity: 0.95; animation: bp-layer-pulse 2.4s ease-in-out infinite 0.3s; }
.bp-db-layer-3 { top: 56px; opacity: 1;    animation: bp-layer-pulse 2.4s ease-in-out infinite 0.6s; }
.bp-db-layer-4 { top: 70px; opacity: 0.9;  animation: bp-layer-pulse 2.4s ease-in-out infinite 0.9s; }

@keyframes bp-layer-pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(0, 240, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
    50%      { box-shadow: 0 0 24px rgba(0, 240, 255, 1), inset 0 1px 0 rgba(255, 255, 255, 0.8); }
}

/* Точки данных в орбите */
.bp-db-bit {
    position: absolute;
    top: 50%; left: 50%;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 8px var(--gold), 0 0 16px var(--gold);
    transform-origin: 0 0;
    animation: bp-bit-orbit 6s linear infinite;
    animation-delay: calc(var(--i) * -1s);
    margin: -3px 0 0 -3px;
}
.bp-db-bit:nth-child(2n) {
    background: var(--electric);
    box-shadow: 0 0 8px var(--electric), 0 0 16px var(--electric);
    animation-duration: 4s;
}

@keyframes bp-bit-orbit {
    0%   { transform: translate(40px, 0) rotate(0deg); }
    100% { transform: translate(40px, 0) rotate(360deg); }
}

/* Центральный пульсирующий ядро */
.bp-db-pulse {
    position: absolute;
    top: 50%; left: 50%;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, var(--electric) 50%, transparent 100%);
    transform: translate(-50%, -50%);
    box-shadow:
        0 0 16px var(--electric),
        0 0 32px rgba(0, 240, 255, 0.6);
    animation: bp-db-pulse-anim 2s ease-in-out infinite;
    z-index: 3;
}

@keyframes bp-db-pulse-anim {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
    50%      { transform: translate(-50%, -50%) scale(1.4); opacity: 1; }
}

.bp-db-label {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--electric);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.7);
    margin-top: 8px;
}

/* === МОЗГ === */
.bp-brain {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
}

.bp-brain::after {
    content: "";
    position: absolute;
    width: 180px;
    height: 180px;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(255, 215, 0, 0.18) 0%, transparent 60%);
    pointer-events: none;
    animation: bp-brain-glow 4s ease-in-out infinite;
    z-index: -1;
}

@keyframes bp-brain-glow {
    0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
    50%      { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

.bp-brain svg {
    width: 110px;
    height: 110px;
    overflow: visible;
    filter: drop-shadow(0 0 16px rgba(255, 215, 0, 0.5));
    transition: transform 0.3s var(--ease-out-quart);
}

.bp-brain.is-active svg {
    transform: scale(1.06);
    filter: drop-shadow(0 0 20px rgba(0, 240, 255, 0.6));
}

.bp-brain-outline {
    fill: rgba(255, 215, 0, 0.05);
    stroke: var(--gold);
    stroke-width: 1.5;
    opacity: 0.7;
}

.bp-neuron {
    fill: var(--gold);
    animation: bp-neuron-pulse 2.4s ease-in-out infinite;
    animation-delay: var(--neuron-delay, 0s);
    filter: drop-shadow(0 0 4px var(--gold));
    transform-origin: center;
    transform-box: fill-box;
}

@keyframes bp-neuron-pulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50%      { opacity: 1; transform: scale(1.4); fill: var(--electric); }
}

.bp-synapse {
    stroke: var(--gold);
    stroke-width: 1;
    stroke-dasharray: 4 4;
    opacity: 0.4;
    animation: bp-synapse-flow 3s linear infinite;
    animation-delay: var(--syn-delay, 0s);
}

@keyframes bp-synapse-flow {
    0%   { stroke-dashoffset: 0; opacity: 0.2; }
    50%  { opacity: 0.8; stroke: var(--electric); }
    100% { stroke-dashoffset: -16; opacity: 0.2; }
}

.bp-brain-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

/* === BLOOMBERG ОТВЕТ - WOW версия === */
.bp-answer {
    grid-area: answer;
    background:
        linear-gradient(180deg, #0a0e14 0%, #050810 100%);
    border: 1px solid rgba(0, 240, 255, 0.2);
    border-radius: 14px;
    overflow: hidden;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.6),
        0 0 32px rgba(0, 240, 255, 0.08),
        inset 0 0 20px rgba(0, 240, 255, 0.06);
    z-index: 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* Скан-линия по горизонтали (terminal эффект) */
.bp-answer::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--electric) 50%,
        transparent 100%);
    animation: bp-scanline 4s linear infinite;
    pointer-events: none;
    z-index: 4;
    opacity: 0.6;
}
@keyframes bp-scanline {
    0%   { transform: translateY(0); opacity: 0; }
    10%  { opacity: 0.6; }
    90%  { opacity: 0.6; }
    100% { transform: translateY(280px); opacity: 0; }
}

html.light-theme .bp-answer {
    background: linear-gradient(180deg, #fff 0%, #f5f1e8 100%);
}

.bp-answer-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background:
        linear-gradient(180deg,
            rgba(0, 240, 255, 0.08) 0%,
            rgba(0, 240, 255, 0.02) 100%);
    border-bottom: 1px solid rgba(0, 240, 255, 0.18);
    flex-shrink: 0;
}

.bp-answer-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.bp-answer-dot-red    { background: #ff5f57; box-shadow: 0 0 8px rgba(255, 95, 87, 0.5); }
.bp-answer-dot-yellow { background: #febc2e; box-shadow: 0 0 8px rgba(254, 188, 46, 0.5); }
.bp-answer-dot-green  { background: #28c840; box-shadow: 0 0 8px rgba(40, 200, 64, 0.5); }

.bp-answer-title {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--electric);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.bp-answer-title::before {
    content: "●";
    color: #28c840;
    font-size: 8px;
    animation: bp-status-blink 1.4s ease-in-out infinite;
}
@keyframes bp-status-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

.bp-answer-body {
    flex: 1;
    padding: 18px 22px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.75;
    color: #b8e8ff;
    position: relative;
    overflow: hidden;
    min-height: 220px;
}

/* Background grid - subtle */
.bp-answer-body::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 240, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 240, 255, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
}

.bp-answer-text {
    margin: 0;
    white-space: pre-wrap;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    word-break: break-word;
    position: relative;
    z-index: 1;
}

.bp-answer-text .bp-num {
    color: var(--gold);
    font-weight: 700;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.5);
}
.bp-answer-text .bp-pct {
    color: #4ade80;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}
.bp-answer-text .bp-arrow {
    color: var(--gold);
    font-weight: 700;
    margin-right: 6px;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.6);
}

.bp-answer-cursor {
    display: inline-block;
    width: 8px;
    height: 1em;
    background: var(--gold);
    margin-left: 2px;
    vertical-align: text-bottom;
    box-shadow: 0 0 6px var(--gold);
    animation: bp-cursor-blink 0.9s steps(2, start) infinite;
    position: relative;
    z-index: 1;
}

@keyframes bp-cursor-blink {
    0%, 49%  { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* Status bar внизу терминала */
.bp-answer-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    border-top: 1px solid rgba(0, 240, 255, 0.15);
    background: rgba(0, 240, 255, 0.04);
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.bp-answer-stat {
    display: flex;
    align-items: center;
    gap: 5px;
}
.bp-answer-stat-icon {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #28c840;
    box-shadow: 0 0 6px #28c840;
}
.bp-answer-stat-electric .bp-answer-stat-icon { background: var(--electric); box-shadow: 0 0 6px var(--electric); }
.bp-answer-stat-gold .bp-answer-stat-icon { background: var(--gold); box-shadow: 0 0 6px var(--gold); }

/* === ЛЕТЯЩИЕ ЧАСТИЦЫ - яркие с trail === */
.bp-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    overflow: visible;
}

.bp-particle {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, var(--gold) 50%, transparent 100%);
    box-shadow:
        0 0 8px var(--gold),
        0 0 16px rgba(255, 215, 0, 0.5);
    opacity: 0;
    animation: bp-particle-fly 2.2s cubic-bezier(0.45, 0.05, 0.55, 0.95) forwards;
    will-change: transform, opacity;
}

.bp-particle.bp-particle-electric {
    background: radial-gradient(circle, #fff 0%, var(--electric) 50%, transparent 100%);
    box-shadow:
        0 0 8px var(--electric),
        0 0 16px rgba(0, 240, 255, 0.5);
}

@keyframes bp-particle-fly {
    0%   { opacity: 0; transform: translate(var(--x-from), var(--y-from)) scale(0.5); }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--x-to), var(--y-to)) scale(1); }
}

/* === Reduced motion === */
@media (prefers-reduced-motion: reduce) {
    .bp-source.is-pulsing,
    .bp-db-cylinder,
    .bp-neuron,
    .bp-synapse,
    .bp-answer-cursor,
    .bp-particle,
    .bp-brain.is-active svg {
        animation: none !important;
        transform: none !important;
    }

    .bp-particles { display: none; }

    .bp-answer-text::before {
        content: "Кто из 37 клиентов купил?\A\A→ 37 ссылок отправлено\A→ 10 переходов (27%)\A→ 2 заявки\A→ 1 покупка\A\A Источник: CRM + SP + платежка";
        white-space: pre;
    }
}

/* === Mobile (vertical Brain Pipeline) === */
@media (max-width: 960px) {
    .brain-pipeline {
        grid-template-areas:
            "sources"
            "core"
            "answer";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 14px;
        padding: 14px;
        min-height: auto;
    }
    .brain-pipeline::before,
    .brain-pipeline::after { display: none; }

    .bp-sources {
        grid-template-columns: repeat(3, 1fr);
        grid-auto-rows: 34px;
    }

    .bp-source {
        font-size: 10px;
        padding: 0 8px;
        height: 34px;
    }

    .bp-source-label { font-size: 10px; }

    .bp-core {
        flex-direction: row;
        gap: 32px;
        padding: 12px 0;
        justify-content: center;
        align-items: center;
    }

    .bp-database, .bp-brain { flex: 0 0 auto; }

    .bp-answer-body { min-height: 160px; }
}

@media (max-width: 480px) {
    .bp-sources {
        grid-template-columns: repeat(2, 1fr);
    }
    .bp-core { gap: 20px; }
    .bp-db-cylinder { width: 56px; height: 70px; }
    .bp-db-top, .bp-db-bottom { width: 56px; height: 18px; }
    .bp-db-side { top: 9px; width: 56px; height: 52px; }
    .bp-brain svg { width: 90px; height: 90px; }
}
