/* =========================================================================
   MantaSys sandbox page (sandbox/index.html): the live demos.
   Loaded after story.css and uses its tokens, bar, rail, headline, demo
   frame (.demo / .chrome / .view / .sketch), feature scenes (.s-demo, .try),
   contact scene and the
   --p / --a / --w timeline (see the top of story.css). story.js loads each
   scene's iframe previews as that scene gets close.
   As there, every animated rule is scoped to html.js, so without the script
   or with reduced motion each scene shows its finished state.
   ========================================================================= */

/* =======================================================================
   01 · Try it: the server is unplugged and the data moves into the tab
   ======================================================================= */

.s-try .stage {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(24px, 4vw, 72px);
  --u: 1;
}
html.js .s-try .stage { --u: clamp(0, (var(--p) - .25) / .35, 1); }
html.js .try-copy .eyebrow { animation: fade-up .9s var(--ease) .05s both; }
html.js .try-copy .premise-lede { animation: fade-up .9s var(--ease) .55s both; }
html.js .try-vis { animation: fade .9s ease .35s both; }

.unplug { width: 100%; height: auto; max-height: 72vh; display: block; overflow: visible; }
.unplug text { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; fill: var(--fg-3); }
.unplug .vlabel { fill: color-mix(in srgb, var(--teal-hi) calc(var(--u) * 100%), var(--fg-3)); }

.cable { fill: none; stroke: var(--fg-4); stroke-width: 2; stroke-dasharray: 6 6; }
.cable-flow {
  fill: none; stroke: var(--teal-hi); stroke-width: 3; stroke-dasharray: 6 22;   /* period matches @keyframes flow (28) */
  animation: flow 1.4s linear infinite;
}
.server rect { fill: var(--bg-2); stroke: var(--fg-3); stroke-width: 1.5; }
.server circle { fill: var(--teal-hi); }
.mem rect { fill: var(--teal-tint); stroke: var(--teal-hi); stroke-width: 1.5; }
.mem-rows { stroke: var(--teal-hi); stroke-width: 4; opacity: .55; }
.unplug .mem text { fill: var(--teal-hi); }

/* Without the script, show the finished state: no server. */
html:not(.js) .server,
html:not(.js) .cable,
html:not(.js) .cable-flow { display: none; }

html.js .cable { opacity: calc(1 - var(--u)); }
html.js .cable-flow { opacity: calc(1 - var(--u) * 2); }
html.js .server {
  opacity: calc(1 - var(--u) * 1.2);
  transform: translateX(calc(var(--u) * 70px));
}
html.js .mem {
  opacity: var(--u);
  transform-box: fill-box; transform-origin: center;
  transform: scale(calc(.85 + var(--u) * .15));
}

/* =======================================================================
   04 · How these work: the production stack beside the demo stack
   ======================================================================= */

.s-how .stage { align-content: center; gap: clamp(24px, 5vh, 48px); }
.how-head .lede { margin-top: 14px; }

.stacks {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: clamp(96px, 12vw, 180px);
  row-gap: 14px;
  max-width: 1040px;
}
.stack-k {
  font-family: var(--mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--fg-2);
}
.stack-k-demo { color: var(--teal-hi); }

.layers { grid-column: 1 / -1; list-style: none; padding: 0; display: grid; gap: 10px; }
.layer {
  position: relative;
  display: grid; grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: clamp(96px, 12vw, 180px);
  align-items: stretch;
  --t: 1;
}
.node {
  display: grid; gap: 2px;
  padding: 14px 18px;
  background: var(--bg-2); border: 1px solid var(--line);
}
.node-k { font-weight: 600; letter-spacing: -.01em; }
.node-v { color: var(--fg-3); font-size: .92rem; line-height: 1.4; }
.node.is-out { background: var(--teal-tint); border-color: var(--teal-hi); }
.node.is-out .node-k { color: var(--teal-hi); }
.node.is-muted { background: transparent; border-style: dashed; border-color: var(--fg-4); }

/* the link between the two: a line with what happened written on it */
.verdict {
  position: absolute; top: 50%; left: 50%;
  width: clamp(96px, 12vw, 180px);
  transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--fg-3); text-align: center;
}
.verdict::after {
  content: ""; width: 100%; height: 1px;
  background: linear-gradient(90deg, var(--fg-4), var(--teal-hi));
  transform: scaleX(var(--t)); transform-origin: left;
}
.is-swap .verdict { color: var(--teal-hi); }

/* the production layers that get replaced fade back as their stand-in arrives */
.is-swap > .node:first-child { opacity: calc(1 - var(--t) * .45); }
.is-swap > .node:first-child .node-k { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--fg-3) calc(var(--t) * 100%), transparent); }

html.js .layer { --t: clamp(0, (var(--p) - var(--a)) / .1, 1); }
html.js .layer > .node:last-child {
  opacity: var(--t);
  transform: translateX(calc((1 - var(--t)) * -40px));
}
html.js .verdict { opacity: var(--t); }

/* =======================================================================
   Smaller and shorter screens
   ======================================================================= */

@media (max-height: 900px) and (min-width: 721px) {
  .how-head .lede { display: none; }
}
@media (max-width: 900px) {
  .s-try .stage { grid-template-columns: minmax(0, 1fr); align-content: center; gap: 18px; }
  .unplug { max-height: 32vh; max-height: 32svh; }
}

@media (max-width: 720px) {
  /* The stacks scroll normally on phones (the demo scenes: see story.css). */
  html.js .s-how { height: auto; }
  html.js .s-how .stage { position: relative; height: auto; overflow: visible; }
  html.js .s-how .rv,
  html.js .layer > .node:last-child,
  html.js .verdict { opacity: 1; transform: none; }
  html.js .layer { --t: 1; }

  .stacks { grid-template-columns: minmax(0, 1fr); }
  .stack-k-demo { display: none; }
  .layer { grid-template-columns: minmax(0, 1fr); row-gap: 6px; }
  .verdict {
    position: static; transform: none; width: auto;
    grid-auto-flow: column; justify-content: start; gap: 10px;
  }
  .verdict::before { content: "\2193"; }
  .verdict::after { display: none; }
}
