/*
 * The 3D hero: the KESS3, and TunerSuite beside it (parts/hero3d.php,
 * js/hero3d-src). Two forms.
 *
 * Static (the default): the first caption beside a render of the tool, the
 * other captions as a strip underneath. Nothing here needs JavaScript, so a
 * phone without WebGL, a visitor who asked for less motion and a search engine
 * all read the whole story.
 *
 * Live (html.h3d, set before paint by the header when the scene can run): a
 * tall section with a sticky stage; the scene and the captions follow the
 * scroll. The stage is dark in both themes (.v3-stage in tokens.css).
 */

.hero3d {
  --h3d-length: 440vh;
  --h3d-top: 65px;
  position: relative;
  padding-block: var(--sp-8);
  background: var(--stage-bg);
  color: var(--stage-ink);
}

.hero3d__pin {
  position: relative;
  display: grid;
  gap: var(--sp-6);
  align-items: center;
  width: min(var(--page-max), 100% - 2 * var(--gutter));
  margin-inline: auto;
}

.hero3d__copy {
  display: contents;
}

.hero3d__cap--intro {
  order: 1;
}

.hero3d__stage {
  position: relative;
  order: 2;
  min-width: 0;
}

.hero3d__more {
  display: grid;
  order: 3;
  gap: var(--sp-4);
}

.hero3d__poster {
  display: block;
  width: 100%;
  height: auto;
}

.hero3d__canvas,
.tag3d,
.hero3d__rail,
.hero3d__hint,
.hero3d__flare,
.hero3d__load {
  display: none;
}

.hero3d__h {
  margin: 0 0 var(--sp-4);
  color: var(--stage-ink);
  font-size: var(--step-5);
  line-height: var(--leading-tight);
}

.hero3d__h b {
  color: var(--stage-accent);
  font-weight: inherit;
}

.hero3d__lead,
.hero3d__p {
  max-width: 34rem;
  margin: 0 0 var(--sp-5);
  color: var(--stage-ink-2);
  font-size: var(--step-1);
  line-height: var(--leading-body);
}

.hero3d__t {
  margin: 0 0 var(--sp-3);
  color: var(--stage-ink);
  font-size: var(--step-3);
  line-height: var(--leading-tight);
}

.hero3d__facts {
  margin: var(--sp-5) 0 0;
  color: var(--stage-ink-2);
}

.hero3d__more .hero3d__cap {
  padding: var(--sp-5);
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-2);
}

.hero3d__more .hero3d__p {
  font-size: var(--step-0);
}

@media (min-width: 760px) {
  .hero3d__more {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .hero3d__pin {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  }

  .hero3d__cap--intro {
    grid-row: 1;
    grid-column: 1;
  }

  .hero3d__stage {
    grid-row: 1;
    grid-column: 2;
  }

  .hero3d__more {
    grid-row: 2;
    grid-column: 1 / -1;
  }
}

/* ---- live -------------------------------------------------------------- */

html.h3d .hero3d {
  height: var(--h3d-length);
  padding-block: 0;
  overflow: clip;
}

html.h3d .hero3d__pin {
  position: sticky;
  top: var(--h3d-top);
  display: block;
  width: auto;
  height: calc(100vh - var(--h3d-top));
  height: calc(100svh - var(--h3d-top));
  overflow: hidden;
}

html.h3d .hero3d__stage {
  position: absolute;
  inset: 0;
}

html.h3d .hero3d__canvas {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.9s var(--ease-out);
}

html.h3d-ready .hero3d__canvas {
  opacity: 1;
}

html.h3d .hero3d__poster {
  position: absolute;
  top: 50%;
  right: 3%;
  width: min(54%, 860px);
  transform: translateY(-50%);
  transition: opacity 0.6s, filter 0.6s;
}

html.h3d-ready .hero3d__poster {
  opacity: 0;
}

/* the edges of the stage held in shadow, and the streak as a light crosses the tool */
html.h3d .hero3d__stage::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  background: var(--stage-vignette);
  pointer-events: none;
  content: "";
}

html.h3d .hero3d__flare {
  position: absolute;
  z-index: 1;
  top: 51%;
  right: -8%;
  left: 34%;
  display: block;
  height: 2px;
  background: var(--stage-flare);
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}

/* the loader: the hexagon draws itself and the bar follows the real download */
html.h3d-loading .hero3d__load {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: 3%;
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  width: min(54%, 860px);
  transform: translateY(-50%);
  pointer-events: none;
}

html.h3d-loading .hero3d__poster {
  opacity: 0.18;
  filter: blur(4px) saturate(0.4);
}

.hero3d__hex {
  width: clamp(84px, 9vw, 128px);
  height: auto;
  overflow: visible;
}

.hero3d__hex polygon {
  fill: none;
  stroke-linejoin: round;
}

.hero3d__hex-a {
  stroke: var(--stage-brand);
  stroke-width: 3;
  stroke-dasharray: 270;
  stroke-dashoffset: 270;
  transition: stroke-dashoffset 0.25s linear;
}

.hero3d__hex-b {
  stroke: var(--stage-line);
  stroke-width: 2;
}

.hero3d__loadt {
  margin: 0;
  color: var(--stage-ink);
  font: 600 var(--step--1) var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero3d__loadt span {
  color: var(--stage-accent);
}

.hero3d__bar {
  display: block;
  width: min(260px, 60%);
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--stage-track);
}

.hero3d__bar i {
  display: block;
  height: 100%;
  background: var(--stage-brand);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.25s linear;
}

/* the copy over the stage, the captions taking turns as the scroll moves */
html.h3d .hero3d__pin::before {
  position: absolute;
  z-index: 1;
  inset: 0 42% 0 0;
  background: var(--stage-scrim);
  pointer-events: none;
  content: "";
}

html.h3d .hero3d__copy {
  position: relative;
  z-index: 2;
  display: grid;
  align-items: center;
  width: min(var(--page-max), 100% - 2 * var(--gutter));
  height: 100%;
  margin-inline: auto;
  pointer-events: none;
}

html.h3d .hero3d__more {
  display: contents;
}

html.h3d .hero3d__cap {
  grid-area: 1 / 1;
  max-width: 35rem;
  pointer-events: auto;
  will-change: opacity, transform;
}

html.h3d .hero3d__more .hero3d__cap {
  padding: 0;
  border: 0;
  opacity: 0;
  visibility: hidden;
}

html.h3d .hero3d__t {
  font-size: var(--step-5);
}

html.h3d .hero3d__more .hero3d__p {
  font-size: var(--step-1);
}

/* the labels that follow the cable ends, and TunerSuite's */
html.h3d .tag3d {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 12px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-pill);
  background: var(--stage-panel);
  color: var(--stage-ink);
  font: 600 var(--step--1) var(--font-mono);
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.tag3d::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--stage-accent);
  content: "";
}

html.h3d .tag3d--ts {
  border-color: var(--stage-brand);
}

/* the rail: one mark per caption, the current one long */
html.h3d .hero3d__rail {
  position: absolute;
  z-index: 3;
  top: 50%;
  right: max(16px, calc((100% - var(--page-max)) / 2));
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  transform: translateY(-50%);
}

.hero3d__rail button {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  min-height: 28px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--stage-quiet);
  font: 600 var(--step--1) var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.hero3d__rail button::after {
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: width var(--dur-2) var(--ease-out);
  content: "";
}

.hero3d__rail button span {
  opacity: 0;
  transform: translateX(6px);
  transition: opacity var(--dur-2), transform var(--dur-2);
}

.hero3d__rail button:hover span,
.hero3d__rail button:focus-visible span,
.hero3d__rail button[aria-current="step"] span {
  opacity: 1;
  transform: none;
}

.hero3d__rail button[aria-current="step"] {
  color: var(--stage-accent);
}

.hero3d__rail button[aria-current="step"]::after {
  width: 44px;
}

.hero3d__rail button:focus-visible {
  border-radius: var(--radius-1);
  outline: 2px solid var(--focus);
  outline-offset: 4px;
}

html.h3d .hero3d__hint {
  position: absolute;
  z-index: 3;
  bottom: var(--sp-4);
  left: 50%;
  display: block;
  margin: 0;
  color: var(--stage-quiet);
  font: 600 var(--step--1) var(--font-mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  transform: translateX(-50%);
  pointer-events: none;
}

.hero3d__hint::after {
  display: block;
  width: 1px;
  height: 26px;
  margin: 6px auto 0;
  background: var(--stage-accent);
  content: "";
}

@media (max-width: 759px) {
  .hero3d {
    --h3d-length: 380vh;
    --h3d-top: 57px;
  }

  html.h3d .hero3d__copy {
    align-items: end;
    padding-bottom: 64px;
  }

  html.h3d .hero3d__pin::before {
    display: none;
  }

  html.h3d .hero3d__pin::after {
    position: absolute;
    z-index: 1;
    inset: 34% 0 0;
    background: var(--stage-scrim-low);
    pointer-events: none;
    content: "";
  }

  html.h3d .hero3d__stage::after {
    background: var(--stage-vignette-low);
  }

  html.h3d .hero3d__poster,
  html.h3d-loading .hero3d__load {
    top: 3%;
    right: 50%;
    width: 98%;
    transform: translateX(50%);
  }

  html.h3d .hero3d__flare {
    top: 31%;
    right: -6%;
    left: -6%;
  }

  html.h3d .hero3d__h,
  html.h3d .hero3d__t {
    font-size: var(--step-4);
  }

  html.h3d .hero3d__lead,
  html.h3d .hero3d__more .hero3d__p {
    font-size: var(--step-0);
  }

  html.h3d .hero3d__facts {
    display: none;
  }

  html.h3d .hero3d__rail {
    top: auto;
    right: 50%;
    bottom: var(--sp-3);
    flex-direction: row;
    gap: 2px;
    transform: translateX(50%);
  }

  .hero3d__rail button {
    justify-content: center;
    min-width: 34px;
  }

  .hero3d__rail button span {
    display: none;
  }

  .hero3d__rail button::after {
    width: 10px;
    height: 10px;
    border-radius: 50%;
  }

  .hero3d__rail button[aria-current="step"]::after {
    width: 26px;
    border-radius: 6px;
  }

  html.h3d .hero3d__hint {
    display: none;
  }

}

@media (prefers-reduced-motion: reduce) {
  .hero3d__canvas,
  .hero3d__bar i,
  .hero3d__hex-a,
  html.h3d .hero3d__poster {
    transition: none;
  }
}
