/* Homepage: work as light, flowing through plumbing.
   Loaded after /styles.css (tokens, type, header, buttons, footer) and only on the homepage,
   so it re-tunes the shared tokens to the VS mark's navy, steel and cyan.
   The 3D scene is drawn by /home3d.js on a pinned, full-bleed canvas (the 2D fallback in /home.js
   uses the same stage). All copy stays in HTML: a left column on desktop, glass captions on phones. */

:root {
  --bg: #060d1c;
  --surface: #0b1830;
  --surface-soft: #0e1f3a;
  --border: #1b3354;
  --text: #e8f3ff;
  --muted: #8ea9c4;
  --muted-strong: #b9cde2;
  --button: #e6f6ff;
  --button-text: #06142a;
  --button-hover: #ffffff;
  --water: #39d0ff;
  --water-ink: #7fdcff;
  --water-soft: rgba(57, 208, 255, 0.12);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --header-h: 77px;
  --scene-bg: #060d1c;
  color-scheme: dark;
}

.home-header {
  position: relative;
  z-index: 3;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Story layout ---------- */

.flow {
  position: relative;
}

.flow-stage {
  position: sticky;
  top: 0;
  z-index: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  pointer-events: none;
  background: var(--scene-bg);
}

.flow-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.flow-steps {
  position: relative;
  z-index: 1;
  margin-top: -100vh;
  margin-top: -100svh;
}

.flow-step {
  display: flex;
  min-height: 100vh;
  min-height: 100svh;
  align-items: center;
  padding: var(--space-8) 0;
}

.flow-step-beat {
  min-height: 86vh;
  min-height: 86svh;
}

.flow-inner {
  width: min(calc(100% - 44px), var(--shell));
  margin: 0 auto;
}

.flow-copy {
  position: relative;
  z-index: 0;
  max-width: 26rem;
}

.flow-copy::before {
  position: absolute;
  inset: -56px -84px;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(6, 13, 28, 0.9), rgba(6, 13, 28, 0.62) 62%, rgba(6, 13, 28, 0));
  content: "";
  pointer-events: none;
}

.flow-copy > p,
.flow-beat p,
.flow-item p {
  color: var(--muted-strong);
}

.flow-copy h2 {
  margin-bottom: var(--space-4);
  font-size: clamp(2.1rem, 3.8vw, 3.1rem);
  line-height: 1.06;
}

.flow-copy > p {
  font-size: var(--step-1);
}

/* ---------- Hero ---------- */

.flow-hero {
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100svh - var(--header-h));
  padding-top: var(--space-7);
}

.flow-hero .flow-copy {
  max-width: 34rem;
}

.flow-hero h1 {
  font-size: clamp(2.6rem, 5.4vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
}

.flow-lede {
  margin-bottom: var(--space-6);
}

.flow-cue {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-8);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.flow-cue:hover {
  color: var(--text);
}

.flow-cue-line {
  position: relative;
  width: 1px;
  height: 44px;
  overflow: hidden;
  background: var(--border);
}

.flow-cue-line::after {
  position: absolute;
  top: -14px;
  left: -1px;
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--water);
  box-shadow: 0 0 8px rgba(57, 208, 255, 0.8);
  content: "";
  animation: flow-drip 2.2s cubic-bezier(0.5, 0, 0.7, 1) infinite;
}

@keyframes flow-drip {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(62px); opacity: 0; }
}

/* ---------- Chapter details ---------- */

.flow-kicker {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.flow-kicker span {
  color: var(--water);
}

/* Stations: a label, a headline, one short line. */
.flow-beat-index {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
  color: var(--water) !important;
  font-family: var(--font-mono);
  font-size: 0.74rem !important;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.flow-beat-index::before {
  width: 22px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 0 6px rgba(57, 208, 255, 0.7);
  content: "";
}

.flow-beat h3 {
  margin-bottom: var(--space-3);
  font-size: clamp(1.75rem, 2.9vw, 2.4rem);
  line-height: 1.1;
}

.flow-beat p {
  margin-bottom: 0;
  font-size: var(--step-1);
}

/* What we build: three cards, each with the icon of the thing it names in the scene. */
.flow-builds {
  display: grid;
  gap: 12px;
  margin-top: var(--space-5);
}

.flow-item {
  position: relative;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 16px;
  align-items: center;
  padding: 16px 18px 16px 16px;
  overflow: hidden;
  border: 1px solid rgba(127, 220, 255, 0.16);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(16, 38, 70, 0.86), rgba(8, 20, 40, 0.86));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(200, 235, 255, 0.06);
  transition: border-color 0.3s ease, transform 0.3s ease;
}

/* A thin line of flow down the leading edge. */
.flow-item::before {
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--water);
  box-shadow: 0 0 10px rgba(57, 208, 255, 0.8);
  content: "";
}

.flow-item:hover {
  border-color: rgba(127, 220, 255, 0.42);
  transform: translateX(3px);
}

.flow-item-icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(57, 208, 255, 0.4);
  border-radius: 50%;
  background: rgba(57, 208, 255, 0.1);
  color: var(--water);
}

.flow-item-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flow-index {
  margin: 0 0 2px;
  color: var(--water) !important;
  font-family: var(--font-mono);
  font-size: 0.7rem !important;
  letter-spacing: 0.14em;
}

.flow-item h3 {
  margin-bottom: 3px;
  font-size: clamp(1.2rem, 1.7vw, 1.4rem);
  line-height: 1.15;
}

.flow-item p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
}

#build .flow-copy {
  max-width: 27rem;
}

.flow-closing h2 {
  font-size: clamp(2.3rem, 4.4vw, 3.4rem);
}

.flow-closing .flow-copy > p {
  margin-bottom: var(--space-6);
}

/* ---------- 3D layers (added by /home3d.js inside the pinned stage) ---------- */

.flow-canvas-3d,
.flow-wash,
.flow-scrim,
.flow-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Light floods the view for a moment as the camera dives into the pipe, and again as it leaves. */
.flow-wash {
  background: radial-gradient(120% 95% at 64% 50%, #a8eaff 0%, #39d0ff 24%, #0e62a6 58%, #06203f 100%);
  opacity: 0;
  will-change: opacity;
}

.flow-canvas-3d {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.9s ease;
}

.flow-canvas-3d.is-ready {
  opacity: 1;
}

/* Keeps the story column readable over the full-bleed scene. */
.flow-scrim {
  background: linear-gradient(90deg, var(--scene-bg) 0%, var(--scene-bg) 22%, rgba(6, 13, 28, 0) 54%);
  opacity: 0.9;
}

.flow-overlay {
  overflow: hidden;
  color: #d9ecff;
}

.callout {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  will-change: transform, opacity;
}

.callout-dot {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--water);
  box-shadow: 0 0 0 4px rgba(57, 208, 255, 0.16), 0 0 12px rgba(57, 208, 255, 0.8);
}

.callout-leg {
  position: absolute;
  top: 0;
  left: 0;
  width: 44px;
  height: 1px;
  background: rgba(127, 220, 255, 0.7);
  transform: rotate(-38deg);
  transform-origin: 0 0;
}

.callout--left .callout-leg {
  transform: rotate(-142deg);
}

/* Tags carry a heavier edge on the pipe side, like a flange. */
.callout-tag {
  position: absolute;
  top: 0;
  left: 0;
  padding: 5px 8px 5px 7px;
  border: 1px solid rgba(127, 220, 255, 0.55);
  border-left: 3px solid var(--water);
  background: rgba(6, 13, 28, 0.8);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  line-height: 1;
  white-space: nowrap;
  transform: translate(38px, calc(-27px - 50%));
}

.callout--left .callout-tag {
  border-right: 3px solid var(--water);
  border-left: 1px solid rgba(127, 220, 255, 0.55);
  transform: translate(calc(-38px - 100%), calc(-27px - 50%));
}

/* How far through the story you are: one quiet line. */
.flow-readout {
  position: absolute;
  top: 32px;
  right: 32px;
  opacity: 0;
  pointer-events: none;
}

.flow-readout-bar {
  position: relative;
  display: block;
  width: 210px;
  height: 1px;
  overflow: hidden;
  background: rgba(142, 169, 196, 0.25);
}

.flow-readout-bar i {
  position: absolute;
  inset: 0;
  background: var(--water);
  box-shadow: 0 0 6px rgba(57, 208, 255, 0.8);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

/* The six stations at a glance, the current one lit. */
.flow-chips {
  position: absolute;
  top: 48px;
  right: 32px;
  opacity: 0;
  pointer-events: none;
}

.flow-chips ol {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.flow-chips li {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(142, 169, 196, 0.3);
  border-radius: 50%;
  background: rgba(8, 20, 40, 0.8);
  color: var(--muted);
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, transform 0.35s ease, box-shadow 0.35s ease;
}

.flow-chips svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flow-chips li.is-done {
  border-color: rgba(57, 208, 255, 0.45);
  color: var(--water);
}

.flow-chips li.is-active {
  border-color: var(--water);
  background: var(--water);
  color: #06142a;
  box-shadow: 0 0 16px rgba(57, 208, 255, 0.5);
  transform: scale(1.12);
}

/* The name under the finished mark. */
.flow-wordmark {
  position: absolute;
  top: 0;
  left: 0;
  padding-left: 0.56em;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.56em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  will-change: transform, opacity;
}

/* Copy rises into place as each chapter arrives (only when JS adds .js-reveal). */
.flow.js-reveal .flow-step .flow-copy > *,
.flow.js-reveal .flow-step .flow-beat > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s ease, transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.flow.js-reveal .flow-step.is-in .flow-copy > *,
.flow.js-reveal .flow-step.is-in .flow-beat > * {
  opacity: 1;
  transform: none;
}

/* The three build cards arrive one after another. */
.flow.js-reveal .flow-step .flow-item {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.6s ease, transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1), border-color 0.3s ease;
}

.flow.js-reveal .flow-step.is-in .flow-item {
  opacity: 1;
  transform: none;
}

.flow.js-reveal .flow-step.is-in .flow-item:hover {
  transform: translateX(3px);
}

.flow.js-reveal .flow-step .flow-item:nth-child(1) { transition-delay: 0.2s, 0.2s, 0s; }
.flow.js-reveal .flow-step .flow-item:nth-child(2) { transition-delay: 0.32s, 0.32s, 0s; }
.flow.js-reveal .flow-step .flow-item:nth-child(3) { transition-delay: 0.44s, 0.44s, 0s; }

.flow.js-reveal .flow-step .flow-beat > *:nth-child(2),
.flow.js-reveal .flow-step .flow-copy > *:nth-child(2) { transition-delay: 0.06s; }
.flow.js-reveal .flow-step .flow-beat > *:nth-child(3),
.flow.js-reveal .flow-step .flow-copy > *:nth-child(3) { transition-delay: 0.12s; }
.flow.js-reveal .flow-step .flow-beat > *:nth-child(4),
.flow.js-reveal .flow-step .flow-copy > *:nth-child(n + 4) { transition-delay: 0.18s; }

/* ---------- After the story ---------- */

.flow-after {
  position: relative;
  z-index: 2;
  background: var(--bg);
}

.flow-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  padding: var(--space-7) 0;
}

.flow-link {
  display: grid;
  gap: 6px;
  padding: var(--space-5) 0 0;
  border-top: 1px solid var(--border);
  transition: border-color 0.3s ease;
}

.flow-link:hover {
  border-top-color: var(--water);
}

.flow-link-kicker {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.flow-link-title {
  color: var(--text);
  font-family: var(--font-serif);
  font-size: var(--step-2);
  font-weight: var(--w-medium);
  line-height: 1.2;
}

.flow-link-title::after {
  display: inline-block;
  margin-left: 0.4em;
  color: var(--water);
  content: "\2192";
  transition: transform 0.3s ease;
}

.flow-link:hover .flow-link-title::after {
  transform: translateX(4px);
}

/* ---------- Phones: the scene fills the whole screen; copy rides on glass captions ---------- */

@media (max-width: 899px) {
  .flow-inner {
    width: min(calc(100% - 24px), var(--shell));
  }

  .flow-step {
    align-items: flex-end;
    padding: var(--space-7) 0 max(18px, env(safe-area-inset-bottom));
  }

  .flow-step-beat {
    min-height: 92vh;
    min-height: 92svh;
  }

  .flow-copy::before {
    display: none;
  }

  .flow-step:not(.flow-hero) .flow-copy {
    max-width: 30rem;
    margin: 0 auto;
    padding: 16px 18px 18px;
    border: 1px solid rgba(143, 200, 255, 0.14);
    border-radius: 16px;
    background: rgba(8, 20, 40, 0.74);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
    backdrop-filter: blur(12px) saturate(1.2);
  }

  .flow-copy h2 {
    margin-bottom: var(--space-2);
    font-size: 1.6rem;
  }

  .flow-copy > p,
  .flow-beat p,
  .flow-item p {
    font-size: 0.97rem;
  }

  .flow-kicker,
  .flow-beat-index {
    margin-bottom: var(--space-2);
    font-size: 0.68rem !important;
  }

  .flow-beat h3 {
    margin-bottom: var(--space-2);
    font-size: 1.38rem;
  }

  /* Inside the glass caption the cards flatten into rows. */
  .flow-builds {
    gap: 0;
    margin-top: var(--space-2);
  }

  .flow-item {
    grid-template-columns: 34px 1fr;
    gap: 12px;
    padding: 9px 0;
    border: 0;
    border-top: 1px solid rgba(127, 220, 255, 0.14);
    border-radius: 0;
    background: none;
    box-shadow: none;
  }

  .flow-item::before {
    display: none;
  }

  .flow-item:hover,
  .flow.js-reveal .flow-step.is-in .flow-item:hover {
    transform: none;
  }

  .flow-item-icon {
    width: 34px;
    height: 34px;
  }

  .flow-item-icon svg {
    width: 17px;
    height: 17px;
  }

  .flow-index {
    display: none;
  }

  .flow-item h3 {
    margin-bottom: 1px;
    font-size: 1.05rem;
  }

  .flow-item p {
    font-size: 0.86rem;
    line-height: 1.35;
  }

  .flow-closing .flow-copy > p {
    margin-bottom: var(--space-4);
  }

  .flow-hero {
    align-items: flex-start;
    min-height: calc(100svh - 132px);
    padding: var(--space-6) 0 var(--space-7);
  }

  .flow-hero .flow-copy {
    padding: var(--space-3) 0 var(--space-4);
  }

  .flow-links {
    grid-template-columns: 1fr;
    gap: 0;
    padding: var(--space-5) 0;
  }

  .flow-link {
    padding: var(--space-4) 0;
  }

  .flow-hero h1 {
    font-size: clamp(2.3rem, 10vw, 3rem);
  }

  /* On the narrowest phones the hero waves can pass behind the last lines of copy. */
  .flow-hero .flow-copy p,
  .flow-hero .flow-cue {
    text-shadow: 0 1px 14px rgba(6, 13, 28, 0.95), 0 0 2px rgba(6, 13, 28, 0.8);
  }

  .flow-cue {
    margin-top: var(--space-5);
  }

  /* A soft wash under the captions; the stage never spills sideways. */
  .flow-scrim {
    background: linear-gradient(to top, var(--scene-bg) 0%, rgba(6, 13, 28, 0) 34%);
    opacity: 0.7;
  }

  .flow-wash {
    background: radial-gradient(150% 75% at 50% 38%, #a8eaff 0%, #39d0ff 24%, #0e62a6 58%, #06203f 100%);
  }

  .flow-readout {
    top: 16px;
    right: auto;
    left: 12px;
  }

  .flow-readout-bar {
    width: 193px;
  }

  .flow-chips {
    top: 30px;
    right: auto;
    left: 12px;
  }

  .flow-chips ol {
    gap: 5px;
  }

  .flow-chips li {
    width: 28px;
    height: 28px;
  }

  .flow-chips svg {
    width: 14px;
    height: 14px;
  }

  .flow-wordmark {
    font-size: 11px;
  }

  .callout-leg {
    display: none;
  }

  .callout-tag,
  .callout--left .callout-tag {
    padding: 4px 6px;
    border: 1px solid rgba(127, 220, 255, 0.55);
    border-bottom: 2px solid var(--water);
    font-size: 9px;
    letter-spacing: 0.1em;
    transform: translate(calc(-50% + var(--nudge, 0px)), calc(-100% - 9px));
  }

  .callout-dot {
    top: -3px;
    left: -3px;
    width: 6px;
    height: 6px;
  }
}

/* Three nav items need a tighter row on phones. */
@media (max-width: 760px) {
  .home-header .nav-actions {
    gap: var(--space-3);
    font-size: 0.88rem;
  }

  .home-header .nav-link,
  .home-header .button-small {
    white-space: nowrap;
  }

  .home-header .button-small {
    padding: 6px 12px;
  }
}

/* "About Chris" is repeated in the hero and footer, so it can step aside on the narrowest phones. */
@media (max-width: 380px) {
  .home-header .nav-link[href^="https://chriscasey.dev"] {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow-cue-line::after {
    animation: none;
    transform: translateY(30px);
    opacity: 1;
  }
}
