/*
 * apps: custom CRMs and business apps (ink field).
 *
 * The drawing is four slabs on an isometric tilt, one per layer of an app. Where each
 * slab sits is one calc() of a few custom properties, so everything that moves it can
 * be added together without any two of them fighting over the transform:
 *   --ap-gap   the distance between slabs (the stack closed or lifted apart)
 *   --ap-drop  how far above its place a slab still is while it is landing
 *   --ap-lift  the extra a slab rises when it is pointed at
 * and the tilt itself leans by --ap-rx / --ap-rz (towards the pointer) and --ap-spin
 * (a few degrees against the scroll).
 *
 * The stylesheet's values are the finished ones: lifted apart, every layer drawn and
 * live (.is-live, which is what turns each layer's accent on). apps.js takes the stack
 * apart and builds it again against the scroll, so without the script the drawing is
 * simply the finished stack. Nothing is hidden here.
 *
 * Only transforms, opacity and a few fills move.
 */

.apps {
  --ap-rule: rgba(238, 237, 232, .2);
  --ap-soft: var(--mist);
  --ap-gap: 68px;
  position: relative;
  overflow-x: clip;
  padding-block: var(--section-y);
}

.apps__top { display: grid; gap: 56px; }
.apps__eyebrow { margin-bottom: 20px; }
.apps__title { max-width: 13ch; }
.apps__line { margin-top: 24px; max-width: 40ch; color: var(--paper); }
.apps__cta { margin-top: 18px; }

/* ---------- the drawing ---------- */

.apps__figure { display: grid; gap: 34px; align-items: center; }
.ap-stack {
  position: relative;
  width: min(100%, 420px);
  /* tall enough for the open stack: the slab's own height on the tilt plus three gaps */
  aspect-ratio: 1 / .92;
  margin-inline: auto;
  padding-bottom: 28px;
  box-sizing: content-box;
  perspective: 1600px;
  perspective-origin: 50% 40%;
}
.ap-stack__tilt {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 34%;
  aspect-ratio: 16 / 10;
  transform: rotateX(calc(58deg + var(--ap-rx, 0deg))) rotateZ(calc(-38deg + var(--ap-rz, 0deg) + var(--ap-spin, 0deg)));
  transform-style: preserve-3d;
}
.ap-layer {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 10px;
  border: 1px solid rgba(238, 237, 232, .3);
  /* top layer highest: 3 gaps up, then 2, 1, 0; plus whatever it is still dropping or lifted by */
  transform: translateZ(calc((3 - var(--i)) * var(--ap-gap) + var(--ap-drop, 0px) + var(--ap-lift, 0px)));
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
  overflow: hidden;
}
.ap-layer__tag {
  position: absolute;
  left: 8px;
  top: 6px;
  z-index: 2;
  font-family: var(--f-display);
  font-weight: 800;
  font-size: .75rem;
  line-height: 1;
}
.ap-layer--1 { background: var(--paper-hi); color: var(--ink); }
.ap-layer--2 { background: var(--graphite); color: var(--paper); }
.ap-layer--3 { background: var(--sand); color: var(--ink); }
.ap-layer--4 { background: var(--cobalt); color: var(--paper); }

/* 1: screens */
.ap-ui__bar { position: absolute; left: 0; right: 0; top: 0; height: 15%; display: flex; align-items: center; gap: 3%; padding: 0 5% 0 13%; border-bottom: 1px solid var(--rule-c); }
.ap-ui__bar i { width: 4%; aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--stone); }
.ap-ui__bar b { margin-left: auto; width: 18%; height: 42%; border-radius: 99px; background: var(--ink); }
.ap-ui__cards { position: absolute; left: 6%; right: 6%; top: 23%; height: 30%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4%; }
.ap-ui__cards i { border-radius: 4px; background: var(--bone); }
.ap-ui__cards i { transition: background-color .35s var(--ease-soft); }
.ap-layer.is-live .ap-ui__cards i:first-child { background: var(--lime); }
.ap-ui__rows { position: absolute; left: 6%; right: 6%; top: 60%; bottom: 9%; display: grid; grid-template-rows: repeat(3, 1fr); gap: 12%; }
.ap-ui__rows i { border-radius: 3px; background: var(--bone); transform-origin: 0 50%; }
.ap-ui__rows i:nth-child(2) { width: 78%; }
.ap-ui__rows i:nth-child(3) { width: 56%; }
/* 2: rules */
.ap-layer--2 svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ap-layer--2 path { fill: none; stroke: var(--mist); stroke-width: 2; vector-effect: non-scaling-stroke; }
.ap-layer--2 rect { fill: var(--night-2); stroke: var(--mist); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ap-layer--2 rect { transition: fill .35s var(--ease-soft), stroke .35s var(--ease-soft); transform-box: fill-box; transform-origin: 50% 50%; }
.ap-layer--2.is-live rect.is-hot { fill: var(--lime); stroke: var(--lime); }
.ap-layer--2.is-live path { stroke: var(--paper); }
.ap-layer--2 path { transition: stroke .35s var(--ease-soft); }
/* 3: data */
.ap-table { position: absolute; inset: 16% 6% 9%; display: grid; grid-template-rows: repeat(5, 1fr); border: 1px solid rgba(17, 17, 16, .35); border-radius: 3px;
  background: repeating-linear-gradient(90deg, transparent 0 calc(25% - 1px), rgba(17, 17, 16, .35) calc(25% - 1px) 25%); }
.ap-table i { border-bottom: 1px solid rgba(17, 17, 16, .35); }
.ap-table i { transform-origin: 0 50%; transition: background-color .35s var(--ease-soft); }
.ap-table i:first-child { background: rgba(17, 17, 16, .16); }
/* The record in use: one row filled in, once the layer is live. */
.ap-layer.is-live .ap-table i:nth-child(3) { background: rgba(17, 17, 16, .82); }
.ap-table i:last-child { border-bottom: 0; }
/* 4: connections */
.ap-ports { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); place-items: center; padding: 14% 8% 6%; }
.ap-ports i { width: 38%; aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--paper); box-shadow: inset 0 0 0 5px var(--cobalt), inset 0 0 0 20px rgba(238, 237, 232, .9); }
.ap-ports i { transition: box-shadow .35s var(--ease-soft), border-color .35s var(--ease-soft); }
.ap-layer.is-live .ap-ports i:nth-child(2), .ap-layer.is-live .ap-ports i:nth-child(6) { box-shadow: inset 0 0 0 5px var(--cobalt), inset 0 0 0 20px var(--lime); border-color: var(--lime); }

/* The build's own status line: which layer is being made, and how far along it is. */
.ap-status {
  position: absolute;
  left: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--ap-soft);
}
.ap-status__dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lime);
}
.ap-status__t { line-height: 1; white-space: nowrap; }
.ap-status__bar {
  flex: none;
  width: 64px;
  height: 2px;
  background: var(--ap-rule);
  overflow: hidden;
}
.ap-status__bar i { display: block; height: 100%; background: var(--lime); transform-origin: 0 50%; }

/*
 * Pointing at a layer (or at its line in the list) lifts it out and quietens the rest.
 * Only once the stack is built (.is-settled, from apps.js): while the scroll is still
 * building it, a transition here would have the slabs trailing behind the scroll.
 */
.ap-stack.is-settled .ap-layer {
  transition: transform .5s var(--ease-out), opacity .3s var(--ease-soft), box-shadow .3s var(--ease-soft);
  cursor: default;
}
.ap-stack.has-focus .ap-layer { opacity: .42; }
.ap-stack.has-focus .ap-layer.is-focus {
  --ap-lift: 26px;
  opacity: 1;
  box-shadow: 0 0 0 1px var(--lime), 0 0 0 1px rgba(0, 0, 0, .25);
}

/* the layers, in words */
.ap-legend {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--ap-rule);
}
.ap-legend__row {
  position: relative;
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr);
  gap: 2px 8px;
  align-items: baseline;
  padding: 13px 0;
  border-bottom: 1px solid var(--ap-rule);
}
.ap-legend__n {
  grid-row: 1 / span 2;
  font-family: var(--f-display);
  font-weight: 800;
  font-stretch: 75%;
  font-size: var(--fs-label);
  color: var(--lime);
}
.ap-legend__name {
  font-family: var(--f-display);
  font-weight: 800;
  font-stretch: 92%;
  font-size: clamp(1.25rem, 1rem + .9vw, 1.75rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
}
.ap-legend__note { grid-column: 2; font-size: var(--fs-small); line-height: 1.4; color: var(--ap-soft); }
/* The line for the layer being pointed at: a lime rule draws across under it. */
.ap-legend__row::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--lime);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform .45s var(--ease-out);
}
.ap-legend__row.is-focus::after { transform: scaleX(1); }
.ap-legend__name { transition: color .25s var(--ease-soft); }
.ap-legend__row.is-focus .ap-legend__name { color: var(--lime); }
.ap-legend.is-live .ap-legend__row { cursor: default; }

/* ---------- what we build, and the example ---------- */

.apps__bottom {
  display: grid;
  gap: 44px;
  margin-top: clamp(64px, 8vw, 128px);
  padding-top: clamp(28px, 3.4vw, 48px);
  border-top: 1px solid var(--ap-rule);
}
.apps__list-label { margin-bottom: 18px; }
.ap-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--gutter);
  margin: 0;
  padding: 0;
  list-style: none;
}
.ap-items__t { display: inline-block; }
.ap-items__item {
  position: relative;
  padding: 11px 0;
  border-bottom: 1px solid var(--ap-rule);
  font-family: var(--f-display);
  font-weight: 650;
  font-stretch: 90%;
  font-size: clamp(.9375rem, .85rem + .4vw, 1.125rem);
  line-height: 1.2;
}
.ap-case {
  align-self: start;
  padding: clamp(22px, 2.6vw, 36px);
  border: 1px solid rgba(238, 237, 232, .32);
  border-radius: 8px;
  background: rgba(238, 237, 232, .04);
}
.ap-case__tag {
  display: inline-block;
  padding: 6px 9px 5px;
  border-radius: 3px;
  background: var(--lime);
  color: var(--ink);
}
.ap-case__name {
  margin-top: 16px;
  font-family: var(--f-display);
  font-weight: 900;
  font-stretch: 100%;
  font-size: clamp(1.75rem, 1.2rem + 1.8vw, 2.75rem);
  line-height: 1;
  letter-spacing: -0.04em;
}
.ap-case__body { margin-top: 14px; font-size: var(--fs-body); line-height: 1.5; color: var(--paper); max-width: 46ch; }

/* ---------- tablet ---------- */

@media (min-width: 768px) {
  .apps__figure { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--gutter); }
  .ap-items { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .apps { --ap-gap: 78px; }
}

/* ---------- desktop ---------- */

@media (min-width: 1024px) {
  .apps__top {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gutter);
    align-items: center;
  }
  .apps__words { grid-column: 1 / 6; }
  .apps__figure { grid-column: 7 / -1; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
  .ap-stack { width: 100%; max-width: 470px; }
  .apps__bottom {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gutter);
  }
  .apps__list { grid-column: 1 / 8; }
  .ap-case { grid-column: 9 / -1; }
}
