/* =============================================================================
   STORY 3D — "So, let's talk." scroll-driven particle narrative (home page)
   Noise → Capture → Conversation → Connection → Growth
   Default (no JS / reduced motion / no WebGL) = readable static chapter list.
   .is-3d (added by js/story3d.js) = pinned, scroll-scrubbed WebGL experience.
   ============================================================================= */

.story3d {
    --s3d-bg: #050B18;
    --s3d-cyan: #5CE1E6;
    --s3d-green: #61CE70;
    --s3d-text: #E6F1FF;
    --s3d-muted: rgba(230, 241, 255, 0.66);
    position: relative;
    padding: 0 !important;
    background: var(--s3d-bg) !important;
    color: var(--s3d-text);
    isolation: isolate;
}

/* Soft blend from the light page into the dark stage and back out */
.story3d::before,
.story3d::after {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 120px;
    z-index: 3;
    pointer-events: none;
}
.story3d::before { top: -1px; background: linear-gradient(180deg, #FFFFFF 0%, rgba(5, 11, 24, 0) 100%); }
.story3d::after  { bottom: -1px; background: linear-gradient(0deg, var(--bg-section, #F8FAFC) 0%, rgba(5, 11, 24, 0) 100%); }

.s3d-stage {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(ellipse 70% 60% at 68% 50%, rgba(92, 225, 230, 0.10) 0%, transparent 70%),
        radial-gradient(ellipse 50% 40% at 15% 85%, rgba(97, 206, 112, 0.06) 0%, transparent 70%),
        var(--s3d-bg);
}

.s3d-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
}

/* ---------- Chapter copy ---------- */
.s3d-chapters {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
    padding: 140px 28px 140px;
    display: grid;
    gap: 28px;
}

.s3d-chapter {
    max-width: 560px;
    padding: 28px 28px 30px;
    border: 1px solid rgba(92, 225, 230, 0.16);
    border-radius: 22px;
    background: linear-gradient(160deg, rgba(15, 30, 55, 0.72), rgba(5, 11, 24, 0.55));
}

.s3d-kicker {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--s3d-cyan);
    margin-bottom: 14px;
}
.s3d-kicker .s3d-num {
    font-variant-numeric: tabular-nums;
    color: rgba(230, 241, 255, 0.45);
}
.s3d-kicker .s3d-num::after {
    content: '';
    display: inline-block;
    width: 22px; height: 1px;
    margin-left: 10px;
    vertical-align: middle;
    background: rgba(92, 225, 230, 0.5);
}

.s3d-chapter h2 {
    font-size: clamp(1.8rem, 3.6vw, 3rem);
    line-height: 1.12;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #FFFFFF;
    margin-bottom: 16px;
}
.s3d-chapter h2 em {
    font-style: normal;
    background: linear-gradient(120deg, var(--s3d-cyan) 10%, var(--s3d-green) 90%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.s3d-chapter p {
    font-size: 16.5px;
    line-height: 1.7;
    color: var(--s3d-muted);
    margin-bottom: 20px;
}

.s3d-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 22px;
}
.s3d-chips span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--s3d-text);
    border: 1px solid rgba(92, 225, 230, 0.22);
    border-radius: 30px;
    background: rgba(92, 225, 230, 0.06);
}
.s3d-chips i { color: var(--s3d-cyan); font-size: 11px; }

.s3d-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14.5px;
    color: var(--s3d-cyan);
    text-decoration: none;
}
.s3d-link i { transition: transform 0.25s ease; }
.s3d-link:hover i { transform: translateX(4px); }

.s3d-ctas {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.s3d-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.s3d-btn.primary {
    background: var(--s3d-cyan);
    color: #031018;
    box-shadow: 0 10px 34px rgba(92, 225, 230, 0.35);
}
.s3d-btn.primary:hover { transform: translateY(-2px); box-shadow: 0 14px 40px rgba(92, 225, 230, 0.5); }
.s3d-btn.ghost {
    color: #FFFFFF;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.04);
}
.s3d-btn.ghost:hover { background: rgba(255, 255, 255, 0.1); }

/* Progress rail + labels + hint are only meaningful in 3D mode */
.s3d-rail,
.s3d-labels,
.s3d-hint { display: none; }

/* =============================================================================
   3D MODE (pinned)
   ============================================================================= */
.story3d.is-3d { height: 560vh; }

.story3d.is-3d .s3d-stage {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100svh;
}

.story3d.is-3d .s3d-canvas { display: block; }

.story3d.is-3d .s3d-chapters {
    position: absolute;
    inset: 0;
    max-width: none;
    padding: 0;
    display: block;
    pointer-events: none;
}

.story3d.is-3d .s3d-chapter {
    position: absolute;
    left: max(28px, calc((100vw - 1200px) / 2 + 28px));
    top: 50%;
    width: min(500px, 42vw);
    padding: 0;
    border: 0;
    background: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(calc(-50% + 34px));
    transition: opacity 0.6s ease, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0.6s;
}
.story3d.is-3d .s3d-chapter.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(-50%);
    transition: opacity 0.6s ease 0.08s, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.08s, visibility 0s;
}
.story3d.is-3d .s3d-chapter.is-past { transform: translateY(calc(-50% - 34px)); }

/* Stagger inner elements of the active chapter */
.story3d.is-3d .s3d-chapter > * {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.story3d.is-3d .s3d-chapter.is-active > * { opacity: 1; transform: none; }
.story3d.is-3d .s3d-chapter.is-active > :nth-child(2) { transition-delay: 0.08s; }
.story3d.is-3d .s3d-chapter.is-active > :nth-child(3) { transition-delay: 0.16s; }
.story3d.is-3d .s3d-chapter.is-active > :nth-child(4) { transition-delay: 0.24s; }
.story3d.is-3d .s3d-chapter.is-active > :nth-child(5) { transition-delay: 0.32s; }

/* Vertical progress rail */
.story3d.is-3d .s3d-rail {
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: absolute;
    right: max(24px, calc((100vw - 1200px) / 2));
    top: 50%;
    transform: translateY(-50%);
    z-index: 4;
}
.s3d-rail button {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    background: none;
    border: 0;
    padding: 2px 0;
    cursor: pointer;
    font-family: inherit;
    color: rgba(230, 241, 255, 0.4);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.s3d-rail button span { opacity: 0; transform: translateX(6px); transition: opacity 0.3s ease, transform 0.3s ease; }
.s3d-rail button::after {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    border: 1.5px solid rgba(230, 241, 255, 0.35);
    transition: all 0.35s ease;
}
.s3d-rail button:hover span,
.s3d-rail button.is-active span { opacity: 1; transform: none; }
.s3d-rail button.is-active { color: var(--s3d-cyan); }
.s3d-rail button.is-active::after {
    background: var(--s3d-cyan);
    border-color: var(--s3d-cyan);
    box-shadow: 0 0 0 5px rgba(92, 225, 230, 0.15), 0 0 18px rgba(92, 225, 230, 0.6);
}
.s3d-rail button:focus-visible { outline: 2px solid var(--s3d-cyan); outline-offset: 4px; border-radius: 4px; }

/* 3D-anchored labels for the "Connection" network */
.story3d.is-3d .s3d-labels {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}
.s3d-label {
    position: absolute;
    left: 0; top: 0;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    color: #FFFFFF;
    border: 1px solid rgba(92, 225, 230, 0.35);
    border-radius: 20px;
    background: rgba(5, 11, 24, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    will-change: transform, opacity;
}
.s3d-label i { color: var(--s3d-cyan); margin-right: 6px; }
.s3d-label.hub {
    border-color: rgba(97, 206, 112, 0.6);
    color: #031018;
    background: var(--s3d-green);
}
.s3d-label.hub i { color: #031018; }

/* Scroll hint (first chapter only) */
.story3d.is-3d .s3d-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    position: absolute;
    left: 50%;
    bottom: 34px;
    transform: translateX(-50%);
    z-index: 4;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(230, 241, 255, 0.55);
    transition: opacity 0.4s ease;
    pointer-events: none;
}
.s3d-hint i {
    display: block;
    width: 1px; height: 38px;
    background: linear-gradient(180deg, var(--s3d-cyan), transparent);
    animation: s3dHint 1.8s ease-in-out infinite;
    transform-origin: top;
}
.story3d.is-3d .s3d-hint.is-hidden { opacity: 0; }
@keyframes s3dHint {
    0%   { transform: scaleY(0); opacity: 1; }
    60%  { transform: scaleY(1); opacity: 1; }
    100% { transform: scaleY(1); opacity: 0; }
}

/* Hero → story cue */
.s3d-hero-cue {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 44px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #64748B);
    text-decoration: none;
}
.s3d-hero-cue i {
    width: 28px; height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border-color, rgba(0,0,0,0.1));
    color: #0891B2;
    animation: s3dBob 2s ease-in-out infinite;
}
@keyframes s3dBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* =============================================================================
   TABLET & MOBILE — scene on top, glass copy card at bottom
   ============================================================================= */
@media (max-width: 991px) {
    .story3d.is-3d { height: 500vh; }

    .story3d.is-3d .s3d-chapter {
        left: 16px;
        right: 16px;
        top: auto;
        bottom: max(18px, env(safe-area-inset-bottom));
        width: auto;
        max-width: 620px;
        margin: 0 auto;
        padding: 20px 20px 22px;
        border: 1px solid rgba(92, 225, 230, 0.18);
        border-radius: 20px;
        background: linear-gradient(160deg, rgba(12, 26, 48, 0.86), rgba(5, 11, 24, 0.8));
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        transform: translateY(30px);
    }
    .story3d.is-3d .s3d-chapter.is-active { transform: none; }
    .story3d.is-3d .s3d-chapter.is-past { transform: translateY(-16px); }

    .s3d-chapter h2 { font-size: clamp(1.45rem, 5.6vw, 2rem); margin-bottom: 10px; }
    .s3d-chapter p  { font-size: 14.5px; line-height: 1.6; margin-bottom: 14px; }
    .s3d-chips      { margin-bottom: 14px; gap: 6px; }
    .s3d-chips span { font-size: 11.5px; padding: 5px 10px; }
    .s3d-kicker     { margin-bottom: 8px; }
    .s3d-btn        { padding: 12px 18px; font-size: 14px; }

    /* Horizontal rail at the top under the navbar */
    .story3d.is-3d .s3d-rail {
        flex-direction: row;
        gap: 10px;
        right: auto;
        left: 50%;
        top: 96px;
        transform: translateX(-50%);
    }
    .s3d-rail button { padding: 6px 2px; }
    .s3d-rail button span { display: none; }

    .s3d-label { font-size: 10.5px; padding: 4px 9px; }
    .story3d.is-3d .s3d-hint { display: none; }
}

/* Narrow phones: service nodes become icon badges (names are in the chips below) */
@media (max-width: 480px) {
    .s3d-label:not(.hub) {
        font-size: 0;
        width: 30px; height: 30px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }
    .s3d-label:not(.hub) i { font-size: 13px; margin: 0; }
}

@media (max-width: 380px) {
    .s3d-chapter p { font-size: 13.5px; }
    .s3d-chips span:nth-child(n+4) { display: none; }
}

/* Short landscape phones: keep the copy compact */
@media (max-height: 520px) and (orientation: landscape) {
    .story3d.is-3d .s3d-chapter p { display: none; }
    .story3d.is-3d .s3d-rail { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .s3d-hint i, .s3d-hero-cue i { animation: none; }
}
