/* =========================================================
   MapSpective · product flow
   Dark stage with an animated observe → automate pipeline
   ========================================================= */

.flow {
  --bg: #0a0c12;
  --fg: #f4f1e8;
  background: var(--bg);
  color: var(--fg);
  padding: clamp(4rem, 9vw, 8rem) 0 0;
  overflow: hidden;
}
.flow__inner { padding: 0 var(--pad); max-width: 96rem; margin: 0 auto; }

.flow__head { max-width: 52rem; }
.flow__head h2 {
  font-weight: 800; font-size: clamp(2.2rem, 4.8vw, 4.4rem); line-height: 1; letter-spacing: -0.055em;
}
.flow__head p {
  margin-top: 1.4rem; max-width: 40rem;
  font-weight: 300; font-size: clamp(1.05rem, 1.5vw, 1.35rem); line-height: 1.5; color: #a9aebd; letter-spacing: -0.01em;
}

/* ---------- Stage ---------- */
.flow__stage { position: relative; margin-top: clamp(2rem, 4vw, 3.5rem); }

.flow__controls { position: absolute; top: 0; left: 0; z-index: 2; display: flex; gap: 0.6rem; }
.ctl {
  display: inline-flex; align-items: center; gap: 0.7rem; height: 2.7rem; padding: 0 1rem;
  background: rgba(10, 12, 18, 0.7); backdrop-filter: blur(6px);
  border: 1px solid rgba(244, 241, 232, 0.28); color: var(--fg); cursor: pointer;
  font-size: 0.9rem; font-weight: 500; transition: background 0.25s, border-color 0.25s, transform 0.25s var(--spring);
}
.ctl:hover { background: rgba(244, 241, 232, 0.1); border-color: rgba(244, 241, 232, 0.6); }
.ctl:active { transform: scale(0.96); }
.ctl svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ctl svg .i-play { display: none; fill: currentColor; stroke-width: 1.5; }
.ctl.is-paused svg .i-play { display: block; }
.ctl.is-paused svg .i-pause { display: none; }
.ctl[data-flow-replay]:hover svg { animation: spin 0.8s var(--ease); }

.flow__scroller { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.flow__scroller::-webkit-scrollbar { display: none; }
.flow__svg { width: 100%; min-width: 760px; height: auto; }

/* ---------- SVG parts ---------- */
.f-bg-line { stroke: rgba(244, 241, 232, 0.1); stroke-width: 1.4; }
.f-bg-dot { fill: rgba(244, 241, 232, 0.28); }
.f-bg-ring { fill: var(--bg); stroke: rgba(244, 241, 232, 0.3); stroke-width: 1.6; }
.f-bg-glyph { fill: none; stroke: rgba(244, 241, 232, 0.38); stroke-width: 1.4; stroke-linecap: round; }

.f-edge-base { fill: none; stroke: rgba(244, 241, 232, 0.2); stroke-width: 2; stroke-dasharray: 2 9; stroke-linecap: round; }
.f-edge {
  fill: none; stroke: var(--fg); stroke-width: 3.2; stroke-linecap: round;
  stroke-dasharray: 1 2; stroke-dashoffset: 1;
  transition: stroke-dashoffset 1s var(--ease);
}
.f-edge.is-drawn { stroke-dashoffset: 0; }
.f-chev { opacity: 0; transition: opacity 0.3s; }
.f-chev.is-drawn { opacity: 1; transition-delay: 0.8s; }
.f-chev path { fill: none; stroke: var(--fg); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.f-dot { fill: #fff; opacity: 0; }

.fnode { cursor: pointer; }
.fnode .halo {
  fill: none; stroke: rgba(244, 241, 232, 0.25); stroke-width: 1.6; stroke-dasharray: 2 8; stroke-linecap: round;
  transform-box: fill-box; transform-origin: center; transition: stroke 0.4s;
}
.fnode .ring { fill: none; stroke: rgba(244, 241, 232, 0.26); stroke-width: 2; transition: stroke 0.4s; }
.fnode .core {
  fill: #15171d; stroke: rgba(244, 241, 232, 0.14); stroke-width: 2;
  transition: fill 0.5s var(--ease), stroke 0.5s;
}
.fnode .pulse-ring { fill: none; stroke: var(--c); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; }
.fnode .icon { fill: none; stroke: #7a7f8e; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.4s; }

.fnode .f-num { font-family: var(--mono); font-size: 17px; fill: #8a8fa0; text-anchor: end; transition: fill 0.4s; }
.fnode .f-title { font-family: var(--font); font-weight: 700; font-size: 24px; letter-spacing: -0.03em; fill: #fff; text-anchor: middle; transition: opacity 0.4s; }
.fnode .f-sub { font-family: var(--font); font-weight: 300; font-size: 16px; fill: #a9aebd; text-anchor: middle; transition: opacity 0.4s; }

.fnode { --o: 0.42; }
.fnode .f-title, .fnode .f-sub { opacity: var(--o); }
.fnode.is-done { --o: 0.85; }
.fnode.is-active { --o: 1; }

.fnode.is-done .core { fill: #24262e; stroke: rgba(244, 241, 232, 0.3); }
.fnode.is-done .icon { stroke: #d5d8e2; }
.fnode.is-done .ring { stroke: rgba(244, 241, 232, 0.5); }

.fnode.is-active .core { fill: var(--fg); stroke: var(--fg); }
.fnode.is-active .icon { stroke: #0b0c10; }
.fnode.is-active .ring { stroke: var(--c); }
.fnode.is-active .halo { stroke: var(--c); animation: spin 26s linear infinite; }
.fnode.is-active .f-num { fill: var(--fg); }
.fnode.is-active .pulse-ring { animation: nodePulse 2.2s var(--ease) infinite; }

@keyframes nodePulse { 0% { transform: scale(1); opacity: 0.7; } 100% { transform: scale(1.55); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Step tabs ---------- */
.flow__tabs {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
  margin-top: clamp(1rem, 2vw, 2rem);
  border-top: 1px solid rgba(244, 241, 232, 0.14);
}
.ftab {
  position: relative; display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 1.2rem 1.2rem 1.4rem 0; background: none; border: 0; color: #7d8292;
  transition: color 0.4s;
}
.ftab + .ftab { padding-left: 1.2rem; }
.ftab__num { font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.08em; }
.ftab__title { display: block; margin-top: 0.35rem; font-weight: 700; font-size: 1.2rem; letter-spacing: -0.03em; color: inherit; }
.ftab__desc { display: block; margin-top: 0.35rem; font-weight: 300; font-size: 0.95rem; line-height: 1.4; max-width: 17rem; }
.ftab__bar {
  position: absolute; left: 0; right: 0; top: -1px; height: 3px; background: transparent;
}
.ftab + .ftab .ftab__bar { left: 0; }
.ftab__bar i { display: block; height: 100%; width: 0; background: var(--c); }
.ftab:hover { color: #c8ccd8; }
.ftab.is-done { color: #b9bdcb; }
.ftab.is-done .ftab__bar i { width: 100%; }
.ftab.is-active { color: var(--fg); }

/* ---------- Log panel ---------- */
.flow-log {
  margin-top: clamp(1.4rem, 2.6vw, 2.4rem);
  border: 1px solid rgba(244, 241, 232, 0.16); background: rgba(244, 241, 232, 0.03);
  max-width: 54rem;
}
.flow-log__bar {
  display: flex; align-items: center; gap: 0.45rem; padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(244, 241, 232, 0.12);
  font-family: var(--mono); font-size: 0.78rem; color: #8a8fa0;
}
.flow-log__bar i { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: #3a3d48; }
.flow-log__bar i:nth-child(1) { background: var(--red); }
.flow-log__bar i:nth-child(2) { background: var(--yellow); }
.flow-log__bar i:nth-child(3) { background: #f4f1e8; }
.flow-log__bar span { margin-left: 0.6rem; }
.flow-log__body {
  min-height: 9.4rem; padding: 1.1rem 1.2rem 1.3rem;
  font-family: var(--mono); font-size: clamp(0.78rem, 1.2vw, 0.92rem); line-height: 1.95; color: #d8dbe6;
}
.log-line { display: block; white-space: pre-wrap; word-break: break-word; animation: logIn 0.45s var(--ease) both; }
.log-line .k { color: var(--c, #4d7bff); }
.log-line .m { color: #7d8292; }
.log-line .ok { color: #7ee2a8; }
.log-line .hl { color: var(--yellow); }
.log-line::before { content: "› "; color: #5d6172; }
@keyframes logIn { from { opacity: 0; transform: translateX(-10px); } }

/* ---------- Command marquee ---------- */
.marquee {
  margin-top: clamp(3rem, 6vw, 5.5rem); padding: 1.5rem 0;
  border-top: 1px solid rgba(244, 241, 232, 0.12); overflow: hidden;
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}
.marquee__track { display: flex; gap: 1rem; width: max-content; animation: marquee 38s linear infinite; }
.marquee:hover .marquee__track { animation-play-state: paused; }
.pill {
  display: inline-flex; align-items: center; gap: 0.7rem; padding: 0.7rem 1.2rem;
  border: 1px solid rgba(244, 241, 232, 0.2); border-radius: 999px;
  font-family: var(--mono); font-size: 0.95rem; color: #e6e8f0; white-space: nowrap;
}
.pill::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--c); box-shadow: 0 0 12px var(--c); }
@keyframes marquee { to { transform: translateX(-50%); } }

@media (max-width: 900px) {
  .flow__tabs { grid-template-columns: 1fr 1fr; }
  .ftab, .ftab + .ftab { padding: 1rem 1rem 1.1rem 0; }
  .ftab__desc { display: none; }
  .flow__controls { position: static; margin-bottom: 0.8rem; }
}

/* ---------- progress ring, chips, ambient glow ---------- */
.fnode .prog {
  fill: none; stroke: var(--c); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 1 2; stroke-dashoffset: 1; opacity: 0; transition: opacity 0.3s;
}
.fnode.is-active .prog, .fnode.is-done .prog { opacity: 1; }
.fnode.is-done .prog { stroke: rgba(244, 241, 232, 0.55); }

.chip-in { transform-box: fill-box; transform-origin: center bottom; transform: scale(0) translateY(14px); opacity: 0; transition: transform 0.6s var(--spring), opacity 0.3s; }
.fnode.is-active .chip-in { transform: scale(1) translateY(0); opacity: 1; }
.fnode.is-active .chip { animation: chipFloat 3s ease-in-out infinite; }
.chip-bg { fill: var(--c); }
.chip-t { font-family: var(--mono); font-weight: 500; font-size: 14px; text-anchor: middle; fill: #0b0c10; }
@keyframes chipFloat { 50% { transform: translate(0, -116px); } }

.fnode.is-active .core { animation: corePop 0.7s var(--spring); transform-box: fill-box; transform-origin: center; }
@keyframes corePop { 0% { transform: scale(0.86); } 100% { transform: scale(1); } }

.flow { position: relative; isolation: isolate; }
.flow::before, .flow::after {
  content: ""; position: absolute; z-index: -1; width: 46vw; aspect-ratio: 1; border-radius: 50%; filter: blur(60px); opacity: 0.35;
}
.flow::before { left: -12vw; top: 8%; background: radial-gradient(closest-side, #0a39b2, transparent); animation: glowA 16s ease-in-out infinite alternate; }
.flow::after { right: -14vw; top: 38%; background: radial-gradient(closest-side, #ee3524 0%, transparent); opacity: 0.22; animation: glowB 19s ease-in-out infinite alternate; }
@keyframes glowA { to { transform: translate(14vw, 22vw) scale(1.2); } }
@keyframes glowB { to { transform: translate(-16vw, -14vw) scale(1.15); } }

.flow__head h2 .w { display: inline-block; overflow: hidden; vertical-align: top; padding-bottom: 0.14em; margin-bottom: -0.14em; }
.flow__head h2 .w > span { display: inline-block; transform: translateY(115%); transition: transform 1s var(--ease); transition-delay: calc(var(--i) * 0.06s); }
.flow__head.in h2 .w > span { transform: none; }

/* =========================================================
   3D agentic flow (flow3d.js) · falls back to the SVG above
   ========================================================= */
.flow3d {
  position: relative; z-index: 1;
  width: 100vw; margin-left: calc(50% - 50vw);
  height: clamp(460px, 52vw, 720px);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 9%, #000 88%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 9%, #000 88%, transparent);
}
.flow3d__canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.flow3d__labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.flow__scroller { display: none; }
.flow-2d .flow__scroller { display: block; }
.flow-2d .flow3d { display: none; }
.flow__stage .flow__controls { z-index: 3; }

.f3-label {
  position: absolute; left: 0; top: 0; transform-origin: 50% 0;
  display: grid; justify-items: center; gap: 0.1rem;
  padding: 0.3rem 0.6rem; background: none; border: 0; color: var(--fg);
  pointer-events: auto; cursor: pointer; white-space: nowrap;
  opacity: 0.4; transition: opacity 0.5s var(--ease);
  will-change: transform;
}
.f3-label.is-done { opacity: 0.8; }
.f3-label.is-active { opacity: 1; }
.f3-label__num { font-family: var(--mono); font-size: 0.85rem; color: var(--c); letter-spacing: 0.08em; }
.f3-label__title { font-weight: 800; font-size: clamp(1.4rem, 2.3vw, 2rem); letter-spacing: -0.045em; line-height: 1.05; text-shadow: 0 2px 18px rgba(10, 12, 18, 0.9); }
.f3-label__sub { font-weight: 300; font-size: clamp(0.9rem, 1.2vw, 1.05rem); color: #a9aebd; text-shadow: 0 2px 12px rgba(10, 12, 18, 0.9); }
.f3-label:hover { opacity: 1; }

.f3-chip { position: absolute; left: 0; top: 0; will-change: transform; }
.f3-chip > span {
  display: block; padding: 0.55rem 1.1rem; border-radius: 999px;
  background: var(--c); color: var(--ink, #0b0c10); font-family: var(--mono); font-weight: 500; font-size: clamp(0.78rem, 1.1vw, 0.95rem); white-space: nowrap;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--c) 18%, transparent), 0 14px 40px -10px var(--c);
  transform-origin: 50% 100%; transform: scale(0) translateY(14px); opacity: 0;
  transition: transform 0.6s var(--spring), opacity 0.3s;
}
.f3-chip.is-active > span { transform: none; opacity: 1; animation: f3chip 3s ease-in-out 0.6s infinite; }
@keyframes f3chip { 50% { transform: translateY(-6px); } }

@media (max-width: 900px) {
  .flow3d { height: clamp(420px, 110vw, 560px); }
  .f3-label__sub { display: none; }
}

/* ---------- 3D stage HUD: caption + on-canvas controls ---------- */
.flow3d { -webkit-mask-image: linear-gradient(180deg, transparent, #000 6%, #000 94%, transparent); mask-image: linear-gradient(180deg, transparent, #000 6%, #000 94%, transparent); }

/* floating station labels only in the wide overview; close-ups use the caption */
.f3-label { opacity: 0; pointer-events: none; transition: opacity 0.5s var(--ease); }
.flow3d__labels.is-overview .f3-label { opacity: 0.85; pointer-events: auto; }
.flow3d__labels.is-overview .f3-label:hover { opacity: 1; }

.flow-hud { display: none; }
.is-3d .flow-hud {
  display: grid; gap: 0.2rem; position: absolute; z-index: 3; left: 0; bottom: clamp(1.4rem, 4vw, 3rem);
  max-width: min(30rem, 60%); pointer-events: none;
}
.flow-hud__num { font-family: var(--mono); font-size: 0.85rem; letter-spacing: 0.1em; color: var(--c, #f4f1e8); }
.flow-hud__title { font-weight: 800; font-size: clamp(2rem, 4.4vw, 3.6rem); line-height: 1; letter-spacing: -0.055em; color: #fff; text-shadow: 0 4px 30px rgba(10, 12, 18, 0.9); }
.flow-hud__sub { font-weight: 300; font-size: clamp(0.95rem, 1.4vw, 1.2rem); color: #c3c7d4; text-shadow: 0 2px 16px rgba(10, 12, 18, 0.95); }
.flow-hud.is-in > * { animation: hudIn 0.7s var(--ease) both; }
.flow-hud.is-in > :nth-child(2) { animation-delay: 0.06s; }
.flow-hud.is-in > :nth-child(3) { animation-delay: 0.12s; }
@keyframes hudIn { from { opacity: 0; transform: translateY(14px); } }

.ctl--3d { display: none; }
.is-3d .flow__controls {
  top: auto; left: auto; right: 0; bottom: clamp(1.4rem, 4vw, 3rem); z-index: 4; align-items: center;
  padding: 0.4rem; gap: 0.4rem; border-radius: 999px;
  background: rgba(14, 16, 24, 0.72); border: 1px solid rgba(244, 241, 232, 0.16);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.8);
}
.is-3d .ctl--3d { display: inline-flex; }
.is-3d .ctl { border-radius: 999px; background: transparent; border-color: rgba(244, 241, 232, 0.22); height: 2.6rem; }
.is-3d .ctl:hover { background: rgba(244, 241, 232, 0.12); }
.is-3d .ctl[data-flow-toggle] { background: #f4f1e8; color: #0b0c10; border-color: #f4f1e8; }
.is-3d .ctl[data-flow-toggle]:hover { background: #fff; }
.ctl--icon { width: 2.6rem; padding: 0; justify-content: center; }
.ctl-count { padding: 0 0.8rem 0 0.4rem; font-family: var(--mono); font-size: 0.85rem; color: #a9aebd; white-space: nowrap; }

@media (max-width: 900px) {
  .is-3d .flow__controls { position: absolute; left: 50%; right: auto; top: 0.6rem; bottom: auto; transform: translateX(-50%); }
  .is-3d .ctl__label { display: none; }
  .is-3d .ctl { width: 2.6rem; padding: 0; justify-content: center; }
  .ctl-count { display: none; }
  .is-3d .flow-hud { max-width: 100%; bottom: 1rem; }
  .flow3d { -webkit-mask-image: none; mask-image: none; }
}
.flow3d__labels:not(.is-overview) .f3-label { opacity: 0; pointer-events: none; }

/* no flash before the first 3D frame: dark stage, labels hidden until positioned */
.flow3d { background: #0a0c12; }
.flow3d:not(.is-ready) .flow3d__labels { visibility: hidden; }
.flow3d:not(.is-ready) .flow3d__canvas { opacity: 0; }
.flow3d__canvas { transition: opacity 0.6s var(--ease); }

/* edge fade applies to the 3D canvas only, so chips/labels near the edges stay fully bright */
.flow3d { -webkit-mask-image: none; mask-image: none; }
.flow3d__canvas {
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 6%, #000 94%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 6%, #000 94%, transparent);
}

/* step chip lives in the caption, never on top of the 3D scene */
.f3-chip { display: none; }
.flow-hud__chip {
  justify-self: start; display: inline-flex; align-items: center; gap: 0.6rem; margin-top: 0.7rem;
  padding: 0.5rem 0.95rem 0.5rem 0.75rem; border-radius: 999px;
  background: rgba(14, 16, 24, 0.78); border: 1px solid color-mix(in srgb, var(--c, #f4f1e8) 45%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px -14px color-mix(in srgb, var(--c, #f4f1e8) 60%, transparent);
}
.flow-hud__chip i {
  width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--c, #f4f1e8);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, #f4f1e8) 25%, transparent); animation: demoRec 1.6s ease-in-out infinite;
}
.flow-hud__chip code { font-family: var(--mono); font-size: clamp(0.8rem, 1.1vw, 0.95rem); color: color-mix(in srgb, var(--c, #f4f1e8) 55%, #ffffff); white-space: nowrap; }
@keyframes demoRec { 50% { opacity: 0.35; } }
@media (max-width: 640px) { .flow-hud__chip code { font-size: 0.75rem; } }

/* tighter join between the section intro and the 3D stage */
.is-3d.flow__stage { margin-top: clamp(0.5rem, 1.2vw, 1rem); }
.flow3d { height: clamp(440px, 48vw, 680px); }
.flow3d__canvas {
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 3%, #000 94%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 3%, #000 94%, transparent);
}
