/* ==========================================================================
   Spatial system: one persistent WebGL scene behind the home page.
   States:  html.gl-capable (scene will load)  html.gl-on (scene live)
            html.gl-static  (reduced motion / no WebGL: clean static layout)
   ========================================================================== */

.gl-stage {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.4s cubic-bezier(.2, .7, .2, 1);
}
.gl-on .gl-stage { opacity: 1; }
.gl-stage canvas { display: block; }

body.spatial-home {
  background: radial-gradient(130% 70% at 50% 0%, #142233 0%, #0b131d 46%, #070b12 100%) fixed #070b12;
}
.spatial-home > main,
.spatial-home > footer { position: relative; z-index: 1; }
.spatial-home > .studio-header { z-index: 6; }

/* The old per-section canvas and the isolated 3D document cards are gone. */
.spatial-home .spatial-screen { display: none; }
.spatial-home .spatial-portfolio { clip-path: none; background: transparent; }
.spatial-home .spatial-content { background: transparent; }
.spatial-home .spatial-chapter { overflow: visible; }

/* --- No hard cuts: sections share one continuous field ------------------- */
.spatial-home .spatial-chapter::after { background: none; }
.spatial-home .spatial-opening::after {
  background: radial-gradient(ellipse at 50% 22%, #08101a99, transparent 58%);
}
.spatial-home .spatial-module::before { display: none; }
.spatial-home .spatial-module::after {
  background: radial-gradient(ellipse at 62% 62%, color-mix(in srgb, var(--flow-accent) 8%, transparent), transparent 62%);
  opacity: .35;
  transition: opacity .9s ease;
}
.spatial-home .spatial-module[data-route-active]::after { opacity: .9; }
.spatial-home .spatial-opening > .spatial-opening-links {
  border-top: 0;
  background: linear-gradient(90deg, transparent, #bdded845 30% 70%, transparent) top / 100% 1px no-repeat;
}
.spatial-home .spatial-opening > .spatial-fallback-photo { opacity: .14; mask-image: linear-gradient(180deg, #000 30%, transparent 92%); }
.gl-on .spatial-home .spatial-opening > .spatial-fallback-photo,
.gl-on body.spatial-home .spatial-opening > .spatial-fallback-photo { opacity: 0; }
.spatial-home .spatial-project > .spatial-fallback-photo {
  opacity: .5;
  mask-image: linear-gradient(180deg, transparent 0, #000 26%, #000 64%, transparent 100%);
}
.spatial-home .spatial-project::after {
  background: linear-gradient(0deg, #070b12d9 0%, #0a121c99 30%, transparent 70%);
}
/* Light lower page: dissolve into it instead of cutting. */
.spatial-home .home-content { background: linear-gradient(180deg, transparent 0, var(--studio-paper) 260px); }
.spatial-home .home-content .editorial-industry {
  border-top: 0;
  padding-top: clamp(250px, 30vw, 330px);
  background:
    radial-gradient(ellipse at 5% 30%, #dfeae3, transparent 53%),
    linear-gradient(180deg, transparent 0, #f1f3eb 250px);
}

.spatial-home .home-content .editorial-contact {
  padding-top: clamp(150px, 16vw, 210px);
  background:
    radial-gradient(ellipse at 100% 100%, #2d5047, transparent 70%),
    linear-gradient(180deg, #f1f3eb 0, #20332f 130px) #20332f;
}

/* --- Hero: Living Job Pipeline ------------------------------------------- */
.spatial-home .spatial-route-window--hero { height: clamp(210px, 34svh, 340px); }
.spatial-route-window--hero { touch-action: pan-y; }
.pipe-line {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, #7fe6ff70, #9dffd2b0 50%, #ffd99a70);
  box-shadow: 0 0 12px #9dffd240;
}
.pipe-node {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  display: block;
  border-radius: 50%;
  color: #e6f8fa;
  font: 650 .7rem/1.2 Manrope, system-ui, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
  user-select: none;
  -webkit-user-select: none;
}
.pipe-node[data-node="job"] { left: 16%; }
.pipe-node[data-node="invoice"] { left: 84%; }
.pipe-node::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--node, #7fe6ff);
  background: radial-gradient(circle, color-mix(in srgb, var(--node, #7fe6ff) 70%, white) 0 18%, color-mix(in srgb, var(--node, #7fe6ff) 22%, transparent) 19% 60%, transparent 62%);
  box-shadow: 0 0 22px color-mix(in srgb, var(--node, #7fe6ff) 45%, transparent);
  transition: transform .6s cubic-bezier(.34, 1.56, .64, 1), box-shadow .5s ease, opacity .8s ease;
}
.pipe-node[data-node="evidence"] { --node: #9dffd2; }
.pipe-node[data-node="invoice"] { --node: #ffd99a; }
.pipe-node b {
  position: absolute;
  left: 50%;
  top: calc(100% + 10px);
  transform: translateX(-50%);
  font-weight: 650;
  white-space: nowrap;
  text-shadow: 0 1px 10px #060d14;
  opacity: .88;
}
/* static step feedback (no WebGL): the node for the current step lights up */
[data-hero-phase="leave"] .pipe-node[data-node="job"]::before,
[data-hero-phase="evidence"] .pipe-node[data-node="evidence"]::before,
:is([data-hero-phase="invoice"], [data-hero-phase="done"]) .pipe-node[data-node="invoice"]::before {
  transform: scale(1.3);
  box-shadow: 0 0 34px var(--node);
}
/* live: the WebGL node is drawn underneath; the DOM node is its accessible handle */
.gl-on .pipe-line { opacity: 0; transition: opacity 1s ease; }
.gl-on .pipe-node {
  left: 0;
  top: 0;
  width: calc(var(--node-r, 30px) * 2);
  height: calc(var(--node-r, 30px) * 2);
  cursor: grab;
  touch-action: none;
}
.gl-on .pipe-node::before { opacity: 0; }
.gl-on .pipe-node b { top: calc(100% + 4px); }
.gl-on [data-dragging] .pipe-node { cursor: grabbing; }
.pipe-node:focus-visible { outline: 2px solid #b8e8f2; outline-offset: 6px; }

/* --- Five pathways: full-width bands ------------------------------------- */
.spatial-home .spatial-module { min-height: 0; padding-block: clamp(70px, 12svh, 140px); }
.spatial-home .spatial-module-layout { grid-template-columns: minmax(0, 1fr); gap: clamp(22px, 4svh, 40px); }
.spatial-home .spatial-module:nth-of-type(even) .spatial-module-layout { grid-template-columns: minmax(0, 1fr); }
.spatial-home .spatial-module:nth-of-type(even) .spatial-module-path,
.spatial-home .spatial-module:nth-of-type(even) .spatial-module-copy { grid-area: auto; }
.spatial-home .spatial-module-copy {
  max-width: none;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, .75fr);
  column-gap: clamp(28px, 6vw, 110px);
  align-items: end;
  transition: opacity .6s ease;
}
.spatial-home .spatial-module-copy > .spatial-kicker { grid-column: 1; }
.spatial-home .spatial-module-copy > h3 { grid-column: 1; grid-row: 2 / span 2; max-width: 18ch; }
.spatial-home .spatial-module-copy > p:not(.spatial-kicker) { grid-column: 2; grid-row: 2; margin: 0; }
.spatial-home .spatial-module-copy > .spatial-flow-link { grid-column: 2; grid-row: 3; align-self: start; margin-top: 12px; justify-self: start; }
.spatial-home .spatial-module[data-route-dim] .spatial-module-copy { opacity: .45; }
.spatial-home .spatial-module-path { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 24px; align-items: start; }
.spatial-home .spatial-module-path > .spatial-route-window { grid-column: 1 / -1; }
.spatial-home .spatial-route-window--service { height: clamp(220px, 36svh, 380px); }
.spatial-home .spatial-module .spatial-flow-chain { margin: 0; }
.spatial-home .spatial-module .spatial-run { margin-top: -4px; }

/* static stage (before WebGL / reduced motion): a quiet track of records */
.stage-still {
  position: absolute;
  inset: 22% 4%;
  background:
    radial-gradient(circle, color-mix(in srgb, var(--flow-accent) 55%, transparent) 0 1.2px, transparent 1.6px) 0 0 / 26px 26px;
  mask-image: linear-gradient(90deg, transparent, #000 15% 85%, transparent);
  opacity: .35;
}
.stage-still::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--flow-accent), transparent);
}
.gl-on .stage-still { opacity: 0; transition: opacity 1s ease; }

/* --- Step states: spring + soft bloom ----------------------------------- */
.spatial-flow-chain li::before,
.spatial-route-controls li::before {
  transition: transform .55s cubic-bezier(.34, 1.56, .64, 1), box-shadow .45s ease, background-color .3s ease;
}
.spatial-flow-chain li[aria-current="step"]::before,
.spatial-route-controls li[aria-current="step"]::before {
  transform: scale(1.6);
  box-shadow: 0 0 16px var(--flow-accent, #82f5ea), 0 0 2px 3px #1e4051;
}
.spatial-flow-chain li[aria-current="step"] > strong { color: #fff; }

.spatial-home .spatial-run[aria-pressed="true"] {
  border-color: var(--flow-accent, #b2fff1);
  box-shadow: 0 0 22px color-mix(in srgb, var(--flow-accent, #b2fff1) 40%, transparent);
}
.has-spring { will-change: transform; }
.is-bloom { animation: soft-bloom .9s ease-out; }
@keyframes soft-bloom {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--flow-accent, #a8ebde) 70%, transparent); }
  45% { box-shadow: 0 0 30px 4px color-mix(in srgb, var(--flow-accent, #a8ebde) 35%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.spatial-home :is(.spatial-run, .spatial-action, .spatial-opening-cta):active {
  transform: scale(.96);
}
.spatial-home :is(.spatial-run, .spatial-action, .spatial-opening-cta) {
  transition: transform .5s cubic-bezier(.34, 1.56, .64, 1), box-shadow .4s ease, background-color .3s ease, border-color .3s ease;
}

/* --- Small screens ------------------------------------------------------- */
@media (max-width: 899px) {
  .spatial-home .spatial-module-copy { grid-template-columns: minmax(0, 1fr); }
  .spatial-home .spatial-module-copy > * { grid-column: 1 !important; grid-row: auto !important; }
  .spatial-home .spatial-module-copy > p:not(.spatial-kicker) { margin-top: 13px; }
  .spatial-home .spatial-route-window--service { height: clamp(190px, 30svh, 260px); }
  .spatial-home .spatial-module-path { grid-template-columns: minmax(0, 1fr); row-gap: 12px; }
}
@media (max-width: 560px) {
  .spatial-home .spatial-route-window--hero { height: clamp(180px, 27svh, 230px); }
  .pipe-node { width: 38px; height: 38px; font-size: .62rem; }
  .pipe-node[data-node="job"] { left: 14%; }
  .pipe-node[data-node="invoice"] { left: 86%; }
}

/* live node handles always sit at the WebGL node position (beats static offsets) */
.gl-on .pipe-node[data-node] { left: 0; top: 0; }
.spatial-home .spatial-route-window--hero { overflow: visible; contain: layout; }

/* --- Reduced motion: clean static layout --------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .gl-stage { display: none; }
  .pipe-node::before,
  .spatial-flow-chain li::before,
  .spatial-route-controls li::before,
  .spatial-home :is(.spatial-run, .spatial-action, .spatial-opening-cta) { transition: none; }
  .is-bloom { animation: none; }
  .spatial-home :is(.spatial-run, .spatial-action, .spatial-opening-cta):active { transform: none; }
}
