/* RSG homepage — "Find the thermostat" (interactive exploded engine).

   Default state (no script, or no WebGL): an ordinary section with two still
   pictures, the two explanations and their links. engine.js upgrades it:
     .ex--live   the stage becomes one screen tall and the stills give way to the
                 3D canvas; the section still scrolls like any other;
     .ex--ready  the 3D scene has drawn its first frame, so the controls appear
                 (tabs, sliders, drag to turn, part names under the pointer).
   Colours come from dark.css / hightech.css tokens. CSP is style-src 'self'. */

.ex {
  position: relative;
  background: var(--hx-bg);
}

.ex-stage {
  /* Room kept clear under the engine for the controls. */
  --ex-dock-h: 148px;
  position: relative;
  display: grid;
  min-height: clamp(540px, 82vh, 820px);
  overflow: hidden;
  isolation: isolate;
}

/* The same navy light the product-range stage uses, placed behind the engine. */
.ex-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(46% 58% at 68% 54%, rgba(14, 52, 112, 0.46), transparent 72%),
    radial-gradient(34% 40% at 30% 70%, rgba(40, 48, 62, 0.34), transparent 74%);
  pointer-events: none;
}

/* The pinned stage hands over to the next section without a hard edge. */
.ex-stage::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  z-index: 0;
  height: 16%;
  background: linear-gradient(transparent, var(--hx-bg));
  pointer-events: none;
}

.ex-visual {
  position: absolute;
  inset: 0;
  z-index: -1;
}

/* Still pictures, one per product, stacked on the right. */
.ex-posters {
  position: absolute;
  inset: var(--topbar-h) 0 0 auto;
  display: grid;
  grid-template-rows: 1fr 1fr;
  width: min(58%, 1040px);
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 18%, #000 86%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0%, #000 18%, #000 86%, transparent 100%);
}

.ex-poster {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.ex-canvas {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 700ms var(--ease-expo);
}

.ex--live .ex-canvas {
  display: block;
  /* Sideways drags turn the engine; vertical ones still scroll the page. */
  touch-action: pan-y;
  cursor: grab;
}

.ex-canvas.is-pointing {
  cursor: pointer;
}

.ex-canvas.is-grabbing {
  cursor: grabbing;
}

.ex--ready .ex-canvas {
  opacity: 1;
}

.ex--live .ex-posters {
  display: none;
}

/* Where the engine is centred: the part of the stage the copy leaves free. */
.ex-frame {
  position: absolute;
  inset: var(--topbar-h) 0 var(--ex-dock-h) 40%;
  pointer-events: none;
}

/* ------------------------------------------------------------------ copy */

.ex-copy {
  position: relative;
  z-index: 2;
  display: grid;
  align-content: space-around;
  gap: var(--space-7);
  padding-block: calc(var(--topbar-h) + var(--space-6)) var(--space-8, 64px);
  pointer-events: none;
}

.ex-chapter {
  display: grid;
  gap: var(--space-5);
  max-width: min(32%, 26rem);
  pointer-events: auto;
}

.ex-title {
  font-size: clamp(2.25rem, 1.3rem + 2.9vw, 3.75rem);
  font-weight: 680;
  letter-spacing: var(--tracking-hero);
  line-height: 1.04;
  color: #fff;
  text-wrap: balance;
}

.ex-steps {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ex-step {
  display: none;
}

.ex-step--final {
  display: grid;
  justify-items: start;
  gap: var(--space-5);
}

.ex-step p {
  font-size: 1.0625rem;
  line-height: 1.62;
  color: var(--hx-ink-2);
  text-wrap: pretty;
}

.ex-step .btn {
  min-height: 48px;
  padding-inline: var(--space-5);
}

.ex-note {
  position: absolute;
  z-index: 2;
  left: var(--gutter);
  bottom: var(--space-5);
  max-width: 40ch;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--hx-ink-3);
}

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

.ex--live .ex-stage {
  height: clamp(640px, 100vh, 940px);
  height: clamp(640px, 100svh, 940px);
  min-height: 0;
}

.ex--live .ex-copy {
  align-content: center;
}

/* The chapters share one cell, and inside the first its two captions do too;
   each hands over when the view changes. */
.ex--live .ex-chapter,
.ex--live .ex-step {
  grid-area: 1 / 1;
  opacity: 0;
  visibility: hidden;
  transition: opacity 240ms ease, transform 420ms var(--ease-expo), visibility 0s linear 240ms;
}

.ex--live .ex-chapter {
  align-self: center;
}

.ex--live .ex-steps {
  display: grid;
}

.ex--live .ex-step {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: var(--space-5);
  transform: translateY(10px);
}

.ex--live .ex-chapter.is-active,
.ex--live .ex-chapter.is-active .ex-step.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 420ms ease 120ms, transform 520ms var(--ease-expo) 120ms, visibility 0s;
}

/* ------------------------------------------------------------------ dock */

/* Tabs choose what to look at; the slider under them works whatever is chosen. */
.ex-dock {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: var(--space-5);
  left: 40%;
  display: none;
  justify-items: center;
  gap: var(--space-3);
  padding-inline: var(--gutter);
  pointer-events: none;
}

.ex--ready .ex-dock {
  display: grid;
}

.ex-dock > * {
  pointer-events: auto;
}

.ex-hint {
  font-size: 0.8125rem;
  line-height: 1.3;
  color: var(--hx-ink-3);
  pointer-events: none;
  transition: opacity 400ms ease;
}

.ex--turned .ex-hint {
  opacity: 0;
}

.ex-tabs {
  display: inline-flex;
  max-width: 100%;
  padding: 4px;
  border: 1px solid var(--hx-line-strong);
  border-radius: 999px;
  background: rgba(var(--scrim), 0.82);
}

.ex-tab {
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: 999px;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 560;
  line-height: 1.15;
  color: var(--hx-ink-2);
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease;
}

.ex-tab:hover {
  color: #fff;
}

.ex-tab[aria-pressed="true"] {
  background: var(--hx-blue);
  color: #fff;
}

.ex-tab:focus-visible,
.ex-range:focus-visible {
  outline: 2px solid var(--hx-blue-hi);
  outline-offset: 2px;
}

.ex-ctl {
  display: grid;
  grid-template-columns: auto minmax(120px, 240px) minmax(11ch, auto);
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  min-height: 44px;
  font-size: 0.875rem;
  line-height: 1.2;
}

.ex-ctl[hidden] {
  display: none;
}

.ex-ctl-name {
  color: var(--hx-ink-2);
}

.ex-ctl-value {
  display: grid;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  color: var(--hx-ink-3);
}

.ex-ctl-value b {
  font-weight: 620;
  color: #fff;
}

.ex-ctl-value [data-state] {
  font-size: 0.75rem;
}

.ex-ctl-value [data-state="opening"],
.ex-ctl-value [data-state="open"] {
  color: var(--hx-blue-hi);
}

.ex-range {
  --fill: 0%;
  width: 100%;
  height: 28px;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.ex-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--hx-blue-hi) var(--fill), var(--hx-line-strong) var(--fill));
}

.ex-range::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--hx-blue-hi) var(--fill), var(--hx-line-strong) var(--fill));
}

.ex-range::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border: 2px solid var(--hx-blue-hi);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  -webkit-appearance: none;
  appearance: none;
}

.ex-range::-moz-range-thumb {
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  border: 2px solid var(--hx-blue-hi);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* The name of the part under the pointer. */
.ex-tip {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  padding: 6px 10px;
  border: 1px solid var(--hx-line-strong);
  border-radius: 6px;
  background: rgba(var(--scrim), 0.92);
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.ex-tip.is-on {
  opacity: 1;
}

/* ---------------------------------------------------------------- labels */

.ex-labels {
  position: absolute;
  inset: 0;
  display: none;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}

.ex--ready .ex-labels {
  display: block;
}

.ex-label {
  --lead: 34px;
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--hx-ink);
  opacity: 0;
  transition: opacity 320ms ease;
}

.ex-label.is-on {
  opacity: 1;
}

.ex-label::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

.ex-label::after {
  content: "";
  position: absolute;
  background: rgba(201, 205, 210, 0.5);
}

.ex-label > span {
  position: absolute;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 14px rgba(11, 15, 19, 0.95);
}

.ex-label--r::after,
.ex-label--l::after {
  top: -0.5px;
  width: var(--lead);
  height: 1px;
}

.ex-label--r::after {
  left: 7px;
}

.ex-label--l::after {
  right: 7px;
}

.ex-label--r > span {
  left: calc(var(--lead) + 14px);
  transform: translateY(-50%);
}

.ex-label--l > span {
  right: calc(var(--lead) + 14px);
  transform: translateY(-50%);
}

.ex-label--up::after,
.ex-label--down::after {
  left: -0.5px;
  width: 1px;
  height: var(--lead);
}

.ex-label--up::after {
  bottom: 8px;
}

.ex-label--down::after {
  top: 8px;
}

.ex-label--up > span {
  bottom: calc(var(--lead) + 14px);
  transform: translateX(calc(-50% + var(--shift, 0px)));
}

.ex-label--down > span {
  top: calc(var(--lead) + 14px);
  transform: translateX(calc(-50% + var(--shift, 0px)));
}

.ex-label--far {
  --lead: clamp(76px, 13vh, 132px);
}

.ex-label--hero {
  --lead: clamp(40px, 6vh, 64px);
  font-size: clamp(1.0625rem, 0.95rem + 0.5vw, 1.375rem);
  font-weight: 680;
  letter-spacing: -0.012em;
  color: #fff;
}

.ex-label--hero::before {
  top: -5px;
  left: -5px;
  width: 10px;
  height: 10px;
  background: var(--hx-blue-hi);
}

.ex-label--hero::after {
  background: linear-gradient(rgba(140, 198, 255, 0.2), var(--hx-blue-hi));
}

/* In the whole-engine view the two product labels are the way in to their close-ups. */
.ex-label.is-link > span {
  padding: 7px 14px;
  border: 1px solid rgba(140, 198, 255, 0.55);
  border-radius: 999px;
  background: rgba(var(--scrim), 0.86);
  font-size: 0.9375rem;
  text-shadow: none;
  cursor: pointer;
  pointer-events: auto;
  transition: background-color 180ms ease, border-color 180ms ease;
}

.ex-label-short {
  display: none;
}

.ex-label.is-link > span::after {
  content: " →";
}

.ex-label.is-link > span:hover {
  border-color: var(--hx-blue-hi);
  background: var(--hx-blue);
}

@media (prefers-reduced-motion: no-preference) {
  .ex-label--hero.is-on::before {
    animation: ex-ping 2.2s cubic-bezier(0.16, 1, 0.3, 1) infinite;
  }
}

@keyframes ex-ping {
  from {
    box-shadow: 0 0 0 0 rgba(140, 198, 255, 0.6);
  }
  70%,
  to {
    box-shadow: 0 0 0 16px rgba(140, 198, 255, 0);
  }
}

/* ---------------------------------------------------------------- narrow */

@media (max-width: 900px) {
  .ex-stage {
    --ex-dock-h: 196px;
    min-height: 0;
  }

  /* Caption, engine, controls: however long the caption runs in a given language,
     the engine keeps at least 300px of its own. */
  .ex--live .ex-stage {
    height: max(clamp(620px, 100vh, 820px), calc(var(--ex-copy-h, 0px) + var(--ex-dock-h) + 300px));
    height: max(clamp(620px, 100svh, 820px), calc(var(--ex-copy-h, 0px) + var(--ex-dock-h) + 300px));
  }

  .ex-frame {
    inset: var(--ex-copy-h, 36%) 0 var(--ex-dock-h) 0;
  }

  .ex-copy {
    align-content: start;
    gap: var(--space-6);
    padding-block: calc(var(--topbar-h) + var(--space-5)) var(--space-6);
  }

  .ex-chapter {
    gap: var(--space-4);
    max-width: 34rem;
  }

  .ex-title {
    font-size: clamp(1.875rem, 1.2rem + 3.4vw, 2.5rem);
  }

  .ex-step p {
    font-size: 1rem;
    line-height: 1.55;
  }

  .ex--live .ex-copy {
    align-content: start;
  }

  .ex--live .ex-chapter {
    align-self: start;
  }

  /* Still pictures below the text when nothing is live. */
  .ex-visual {
    position: relative;
    grid-row: 2;
    z-index: 0;
  }

  .ex-posters {
    position: static;
    grid-template-rows: none;
    width: 100%;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .ex-poster {
    height: auto;
  }

  .ex--live .ex-visual {
    position: absolute;
    grid-row: auto;
    z-index: -1;
  }

  .ex-note {
    position: static;
    grid-row: 3;
    max-width: none;
    padding: 0 var(--gutter) var(--space-5);
  }

  .ex--live .ex-note {
    position: absolute;
    right: var(--gutter);
    bottom: var(--space-2);
    left: var(--gutter);
    padding: 0;
    font-size: 0.75rem;
    text-align: center;
  }

  .ex-dock {
    bottom: 52px;
    left: 0;
    gap: var(--space-2);
  }

  /* Room is short: the valve's pill uses its short name. */
  .ex-label.is-link > span:not(.ex-label-short):not(:only-child) {
    display: none;
  }

  .ex-label.is-link > .ex-label-short {
    display: block;
  }

  .ex-tabs {
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    width: 100%;
    max-width: 30rem;
    border-radius: 14px;
  }

  .ex-tab {
    min-height: 44px;
    padding-inline: var(--space-2);
    border-radius: 10px;
    font-size: 0.8125rem;
    text-wrap: balance;
  }

  .ex-ctl {
    grid-template-columns: auto minmax(0, 1fr) minmax(9ch, auto);
    width: 100%;
    max-width: 30rem;
    font-size: 0.8125rem;
  }

  .ex-range {
    height: 44px;
  }

  /* Only the two products are named on a phone; the other callouts would collide. */
  .ex-label:not(.ex-label--hero) {
    display: none;
  }

  .ex-label--hero {
    --lead: 28px;
  }
}
