/* River demo animation on the landing page. Markup in index.html, timeline in river-demo.js. */

/* The stage closes the hero: it rises in after the copy, lit from behind. */
.rd {
    position: relative;
    isolation: isolate;
    margin-top: 1.75rem;
    flex: 1 1 0;
    min-height: 0;
    max-height: 610px;
    display: flex;
    flex-direction: column;
    animation: rd-enter 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.55s both;
}
.rd::before {
    content: '';
    position: absolute;
    z-index: -1;
    inset: -70px 6% 45%;
    background: radial-gradient(ellipse 50% 60% at 50% 30%, rgba(212, 149, 42, 0.3), transparent 70%);
    filter: blur(60px);
    pointer-events: none;
    animation: rd-glow 2.6s ease-out 0.9s both;
}
@keyframes rd-enter {
    from { opacity: 0; transform: translateY(44px) scale(0.975); }
    to { opacity: 1; transform: none; }
}
@keyframes rd-glow {
    from { opacity: 0; }
    to { opacity: 1; }
}

.rd-stage {
    position: relative;
    flex: 1 1 0;
    min-height: 380px;
    border-radius: 18px;
    border: 1px solid var(--border-glass);
    background:
        radial-gradient(ellipse 60% 55% at 72% 40%, rgba(212, 149, 42, 0.09), transparent 70%),
        #0c0c13;
    box-shadow: 0 40px 120px -40px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}
/* a hairline of light along the top edge */
.rd-stage::before {
    content: '';
    position: absolute;
    z-index: 6;
    top: 0;
    left: 14%;
    right: 14%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(232, 178, 84, 0.6), transparent);
    pointer-events: none;
}

.rd-inner {
    position: absolute;
    inset: 0;
    display: grid;
    /* --rd-split opens the chat's column once the hero is over (river-demo.js) */
    grid-template-columns: calc(var(--rd-split, 0) * 40%) minmax(0, 1fr);
    transform-origin: 0 0;
    will-change: transform, opacity;
}

/* ── Chat pane ── */
.rd-chat {
    justify-self: end;
    width: var(--rd-chat-w);
    margin: 16px 0 16px 16px;
    border-radius: 14px;
    background: #fbfbfd;
    color: #1d1d24;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.8);
    font-size: 13.5px;
    line-height: 1.5;
}

.rd-chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #ececf2;
    background: #fff;
}
.rd-avatar {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: #0a0a0f;
    display: grid;
    place-items: center;
    flex: none;
}
.rd-avatar img { width: 15px; height: 15px; filter: invert(1); display: block; }
.rd-chat-head strong { font-weight: 650; font-size: 14px; }
.rd-chat-head span { color: #8a8a99; font-size: 12px; }

.rd-msgs {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 16px 12px;
    overflow: hidden;
    /* older messages fade out under the header instead of being cut */
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 34px);
    mask-image: linear-gradient(to bottom, transparent 0, #000 34px);
}
.rd-msg { display: none; flex: none; }
.rd-msg.on { display: block; animation: rd-rise 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); transition: opacity 0.5s; }
/* the turn before the current question steps back */
.rd-msg.past { opacity: 0.45; }
@keyframes rd-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.rd-user {
    align-self: flex-end;
    max-width: 86%;
    background: #e9ebfb;
    color: #1f2147;
    padding: 8px 12px;
    border-radius: 12px 12px 3px 12px;
}
.rd-bot { max-width: 94%; color: #2a2a33; min-height: 1.5em; }
.rd-bot b { color: #0a0a0f; font-weight: 700; }

/* River's suggested recommendation: a card, with the move it proposes drawn as a route */
.rd-rec {
    align-self: stretch;
    border: 1px solid #e9e9f0;
    border-radius: 12px;
    background: #fff;
    padding: 11px 13px 12px;
    color: #2a2a33;
    box-shadow: 0 1px 2px rgba(22, 22, 40, 0.04), 0 10px 24px -14px rgba(22, 22, 40, 0.28);
    transition: border-color 0.35s, box-shadow 0.35s;
}
.rd-rec-head {
    display: flex;
    align-items: center;
    gap: 7px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #9a6a14;
    margin-bottom: 7px;
}
.rd-rec-head::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d4952a;
    box-shadow: 0 0 0 3px rgba(212, 149, 42, 0.18);
    transition: background 0.35s, box-shadow 0.35s;
}
.rd-rec-body { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.rd-rec-body strong { font-weight: 650; font-size: 14px; color: #0a0a0f; }
.rd-rec-route { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.rd-rec-route span {
    padding: 2px 9px;
    border-radius: 999px;
    background: #f3f3f8;
    color: #4d4d5c;
    white-space: nowrap;
}
.rd-rec-route span:last-child { background: rgba(212, 149, 42, 0.14); color: #7d5410; transition: background 0.35s, color 0.35s; }
.rd-rec-route svg { width: 26px; height: 8px; flex: none; stroke: #d4952a; transition: stroke 0.35s; }
/* stock on the move until it is accepted */
.rd-rec-flow { stroke-dasharray: 3 4; animation: rd-flow 0.7s linear infinite; }
@keyframes rd-flow { to { stroke-dashoffset: -7; } }
.rd-rec-actions { display: flex; align-items: center; gap: 4px; margin-top: 11px; font-size: 12px; font-weight: 600; }
.rd-rec-actions span { padding: 5px 13px; border-radius: 8px; color: #8a8a99; }
.rd-rec-actions .rd-rec-accept {
    background: #d4952a;
    color: #0a0a0f;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 4px 10px -4px rgba(212, 149, 42, 0.7);
    transition: transform 0.12s, background 0.3s, color 0.3s, box-shadow 0.3s;
}
.rd-rec-accept.press { transform: scale(0.94); }
.rd-rec.done { border-color: #cfe9da; box-shadow: 0 1px 2px rgba(22, 22, 40, 0.04), 0 10px 24px -14px rgba(31, 122, 71, 0.35); }
.rd-rec.done .rd-rec-head { color: #1f7a47; }
.rd-rec.done .rd-rec-head::before { background: #1f9d57; box-shadow: 0 0 0 3px rgba(31, 157, 87, 0.16); }
.rd-rec.done .rd-rec-route svg { stroke: #1f9d57; }
.rd-rec.done .rd-rec-route span:last-child { background: #e8f6ee; color: #1f7a47; }
.rd-rec.done .rd-rec-flow { stroke-dasharray: none; animation: none; }
.rd-rec.done .rd-rec-accept { background: #e8f6ee; color: #1f7a47; box-shadow: none; }
.rd-rec.done .rd-rec-accept::before { content: '✓ '; }
.rd-rec.done .rd-rec-dismiss { display: none; }

.rd-chip {
    align-self: flex-start;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: #6b6b7a;
    background: #f1f1f6;
    border: 1px solid #e6e6ee;
    border-radius: 999px;
    padding: 3px 11px 3px 8px;
}
.rd-chip.on { display: inline-flex; align-items: center; gap: 7px; }
.rd-chip i {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.6px solid #d4952a;
    border-right-color: transparent;
    animation: rd-spin 0.7s linear infinite;
}
.rd-chip.done i {
    animation: none;
    border: none;
    background: #1f9d57;
    position: relative;
}
.rd-chip.done i::after {
    content: '';
    position: absolute;
    left: 3.2px;
    top: 1.6px;
    width: 2.4px;
    height: 4.6px;
    border: solid #fff;
    border-width: 0 1.4px 1.4px 0;
    transform: rotate(40deg);
}
@keyframes rd-spin { to { transform: rotate(360deg); } }

.rd-composer {
    margin: 0 12px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #dcdce6;
    background: #fff;
    border-radius: 12px;
    padding: 8px 8px 8px 13px;
    min-height: 44px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.rd-composer.focus { border-color: #d4952a; box-shadow: 0 0 0 3px rgba(212, 149, 42, 0.16); }
.rd-input { flex: 1; min-width: 0; color: #1d1d24; }
.rd-input.empty { color: #a3a3b1; }
.rd-caret {
    display: inline-block;
    width: 1.5px;
    height: 1.1em;
    background: #1d1d24;
    vertical-align: -0.18em;
    margin-left: 1px;
    animation: rd-blink 1s steps(1) infinite;
}
@keyframes rd-blink { 50% { opacity: 0; } }
.rd-send {
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #d4952a;
    display: grid;
    place-items: center;
    transition: transform 0.12s;
}
.rd-send.press { transform: scale(0.86); }
.rd-send svg { width: 14px; height: 14px; display: block; }

/* ── Engine ── */
.rd-engine { position: relative; min-width: 0; min-height: 0; }
.rd-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ── Pointer ── */
.rd-cursor {
    position: absolute;
    left: 0;
    top: 0;
    width: 22px;
    height: 22px;
    pointer-events: none;
    transform-origin: 0 0;
    z-index: 5;
    will-change: transform, opacity;
}
.rd-cursor svg { position: absolute; left: -3px; top: -2px; width: 22px; height: 22px; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.22)); }
.rd-click {
    position: absolute;
    left: -16px;
    top: -16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #d4952a;
    opacity: 0;
}

/* ── Hero text: one line per beat, over the engine while it has the stage ── */
.rd-hero-text p {
    position: absolute;
    z-index: 6;
    left: 30px;
    top: 16px;
    right: 200px;
    margin: 0;
    font-size: clamp(1.15rem, 1.9vw, 1.55rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    will-change: transform, opacity;
}
.rd-hero-text b { font-weight: 600; color: #e8b254; }

/* ── Steps ── */
.rd-steps {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 10px;
    margin-top: 18px;
}
.rd-step {
    appearance: none;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    transition: color 0.3s;
}
.rd-step:hover, .rd-step.active { color: var(--text-primary); }
.rd-step:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 2px; }
.rd-step span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 9px;
    overflow: hidden;
}
.rd-step i {
    display: block;
    height: 100%;
    background: var(--accent);
    transform-origin: 0 50%;
    transform: scaleX(0);
}


.rd-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (max-width: 860px) {
    .rd { flex: none; max-height: none; margin-top: 3rem; }
    /* stage and step bar fill one screen under the nav */
    .rd-stage { flex: none; height: clamp(600px, calc(100svh - 9.5rem), 760px); }
    .rd-inner { grid-template-columns: 1fr; grid-template-rows: calc(var(--rd-split, 0) * 340px) minmax(0, 1fr); }
    .rd-chat { justify-self: stretch; align-self: end; width: auto; height: 328px; margin: 12px 12px 0; font-size: 13px; }
    .rd-chip { font-size: 9.5px; white-space: nowrap; }
    .rd-hero-text p { left: 16px; top: 18px; right: 16px; font-size: 1.3rem; }
    .rd-step { font-size: 0.55rem; letter-spacing: 0.04em; }
    .rd-steps { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    .rd, .rd::before { animation: none; }
    .rd-msg.on { animation: none; }
    .rd-chip i, .rd-caret, .rd-rec-flow { animation: none; }
}
