/* Glide at Slow (M2; frontend/notes/accordion-motion.md, the owner's pick
 * for the phone now the redesign has taken the pictures Wake-up performed;
 * the mock-up is design/accordion-motion.html, style "Glide", speed "Slow").
 * Linked after motion.css.
 *
 * What opens and closes:
 * - a row that opens in place (an account, a strategy): its height eases to
 *   its content (grid rows 0fr to 1fr), what's inside rises 6 px and fades
 *   in, one piece after another, its chevron springs a quarter turn, a press
 *   dips it, and an edge in the money colour draws down it while it's open;
 * - a detail page (a card's ›): it rises in over the page, its cards one
 *   after another, its back springs in, and the same edge draws down it.
 * Closing mirrors opening: the lines go first (last in, first out), then the
 * height folds shut (or the page sinks away), and the chevron and the edge
 * run back. It is quicker than the open, about 0.3 s against 0.58 s: what's
 * read arrives slowly, and gets out of the way.
 *
 * js/glide.js does the class work: .open and .closing on the row (its panel
 * keeps [hidden] while shut, so a closed row reads closed at once, and
 * .closing keeps it drawn while it folds), .gl-enter and .leaving on a
 * detail page. A redraw (a refresh) puts .noanim on what it rebuilds, so an
 * open row or page is drawn open, never opened again.
 *
 * §3 holds: only opacity, a small transform and the panel's own height move;
 * no figure is tweened. Reduced motion is app.css's one block: every
 * transition and animation here stops, and js/glide.js changes state at once. */

:root {
  /* The speed: Slow (2.4) for the open, the mock-up's own figures (1) for the close. */
  --glide: 2.4;
  --glide-shut: 1;
  --gl-open: calc(.24s * var(--glide));     /* the height, or the page: ~0.58 s */
  --gl-lead: calc(.06s * var(--glide));     /* the first piece waits for the height to start */
  --gl-step: calc(.08s * var(--glide));     /* then each next piece */
  --gl-fade: calc(.22s * var(--glide));
  --gl-move: calc(.28s * var(--glide));
  --gl-edge: calc(.28s * var(--glide));
  --gl-chev: calc(.26s * var(--glide));
  --gl-press: calc(.09s * var(--glide));
  --gl-shut: calc(.3s * var(--glide-shut)); /* the fold */
  --gl-wait: calc(.1s * var(--glide-shut)); /* the lines go first */
  --gl-out: calc(.14s * var(--glide-shut));
  --gl-out-step: calc(.05s * var(--glide-shut));
}

/* A redraw draws what's open as open: nothing eases (the refresh path). */
.noanim, .noanim *, .noanim *::before, .noanim *::after { transition: none !important; animation: none !important; }

/* ---- a row that opens in place ----
 * The panel is a one-row grid whose row eases from 0fr to 1fr, so it opens
 * to the content's own height, whatever that is. Shut, it's [hidden]; while
 * it folds, .closing on the row keeps it drawn. */
.gl-panel {
  display: grid; grid-template-rows: 0fr; min-width: 0;
  transition: grid-template-rows var(--gl-shut) var(--ease) var(--gl-wait);
}
.open > .gl-panel { grid-template-rows: 1fr; transition: grid-template-rows var(--gl-open) var(--ease); }
.closing > .gl-panel[hidden] { display: grid !important; }
.gl-in { overflow: hidden; min-height: 0; min-width: 0; }

/* What's inside: each piece rises and fades in after the one before; going,
 * the last goes first. js/glide.js numbers them (--i in, --ri out). */
.gl-item {
  opacity: 0; transform: translateY(var(--rise));
  transition: opacity var(--gl-out) var(--ease) calc(var(--ri, 0) * var(--gl-out-step)),
    transform var(--gl-out) var(--ease) calc(var(--ri, 0) * var(--gl-out-step));
}
.open > .gl-panel .gl-item {
  opacity: 1; transform: none;
  transition: opacity var(--gl-fade) var(--ease) calc(var(--gl-lead) + var(--i, 0) * var(--gl-step)),
    transform var(--gl-move) var(--ease) calc(var(--gl-lead) + var(--i, 0) * var(--gl-step));
}

/* The edge: drawn down the open row in the money colour (ochre on Plaster,
 * amber on Lamplit: --amber is the palette's money colour there), run back
 * up a beat after the lines go. */
.gl-edge { position: relative; }
.gl-edge::before {
  content: ''; position: absolute; left: var(--gl-edge-x, 0); top: 0; bottom: 0; width: 3px; z-index: 1;
  background: var(--amber); pointer-events: none;
  transform: scaleY(0); transform-origin: top;
  transition: transform var(--gl-shut) var(--ease) var(--gl-wait);
}
.gl-edge.open::before { transform: scaleY(1); transition: transform var(--gl-edge) var(--ease); }

/* The chevron: a quarter turn on the spring. */
.gl-chev::after {
  content: '›'; display: inline-block; flex: none; width: 10px; margin-left: 2px; text-align: center;
  font-weight: 600; color: rgb(var(--fg) / .8);
  transition: transform var(--gl-chev) var(--spring);
}
.open > .gl-chev::after { transform: rotate(90deg); }

/* The press: the row dips, and comes back on release. */
.gl-press { transition: transform var(--gl-press) var(--ease); }
.gl-press:active { transform: scale(.985); }

/* The accounts (F-AC1): the row is the edge; on a card the edge sits on the
 * card's own left edge, outside the row's text. Its padding moved inside the
 * panel's inner box, so nothing shows while it's shut. */
.acc-more.gl-panel { padding: 0; border-top-color: transparent; transition: grid-template-rows var(--gl-shut) var(--ease) var(--gl-wait), border-color var(--gl-shut) var(--ease) var(--gl-wait); }
.acc-row.open > .acc-more.gl-panel { border-top-color: #5A463F; transition: grid-template-rows var(--gl-open) var(--ease), border-color var(--gl-open) var(--ease); }
.lpage .acc-row.open > .acc-more.gl-panel { border-top-color: var(--lp-edge); }
.acc-pad { padding: 0 12px 12px; }
.lpage .acc-pad { padding: 0 0 8px; }
.lpage .acc-row { --gl-edge-x: -16px; }
.acc-row { transition: background-color calc(.2s * var(--glide)) var(--ease); }

/* The strategies (F-SL1): the card's words moved into .sbin, the panel's inner box. */
.strats .srow .shead.gl-chev::after { position: absolute; right: 10px; top: 12px; }
.strats .srow .shead.gl-chev { position: relative; padding-right: 26px; }

/* ---- a detail page ----
 * It rises in over the page; its cards follow, one after another; its back
 * springs in. A redraw part-way through carries on where it was (--gl-skip,
 * a negative delay), and a redraw after it has settled draws it still. */
.lpdetail.gl-enter { animation: gl-page var(--gl-open) var(--ease) var(--gl-skip, 0s) both; }
.lpdetail.gl-enter .dback { animation: gl-back var(--gl-chev) var(--spring) calc(var(--gl-lead) + var(--gl-skip, 0s)) both; }
.lpdetail.gl-enter .dscroll > * { animation: gl-in var(--gl-move) var(--ease) calc(var(--gl-lead) + var(--i, 0) * var(--gl-step) + var(--gl-skip, 0s)) both; }
/* In, first to last (--i); out, last to first (--ri); four steps at most. */
.lpdetail .dscroll > :nth-child(2) { --i: 1; }
.lpdetail .dscroll > :nth-child(3) { --i: 2; }
.lpdetail .dscroll > :nth-child(4) { --i: 3; }
.lpdetail .dscroll > :nth-child(n+5) { --i: 4; }
.lpdetail .dscroll > :nth-last-child(2) { --ri: 1; }
.lpdetail .dscroll > :nth-last-child(3) { --ri: 2; }
.lpdetail .dscroll > :nth-last-child(4) { --ri: 3; }
.lpdetail .dscroll > :nth-last-child(n+5) { --ri: 4; }
.lpdetail::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; z-index: 2; pointer-events: none;
  background: var(--amber); transform-origin: top;
}
.lpdetail.gl-enter::before { animation: gl-edge var(--gl-edge) var(--ease) var(--gl-skip, 0s) both; }

/* Going: the cards first (the last first), then the edge and the page. It
 * is drawn, inert, until js/glide.js takes it away. */
.lpdetail.leaving { pointer-events: none; animation: gl-page-out var(--gl-shut) var(--ease) var(--gl-wait) both; }
.lpdetail.leaving .dscroll > * { animation: gl-out var(--gl-out) var(--ease) calc(var(--ri, 0) * var(--gl-out-step)) both; }
.lpdetail.leaving::before { animation: gl-edge-out var(--gl-shut) var(--ease) var(--gl-wait) both; }

@keyframes gl-page { from { opacity: 0; transform: translateY(calc(var(--rise) * 2)); } }
@keyframes gl-page-out { to { opacity: 0; transform: translateY(calc(var(--rise) * 2)); } }
@keyframes gl-in { from { opacity: 0; transform: translateY(var(--rise)); } }
@keyframes gl-out { to { opacity: 0; transform: translateY(var(--rise)); } }
@keyframes gl-back { from { opacity: 0; transform: translateX(var(--rise)); } }
@keyframes gl-edge { from { transform: scaleY(0); } }
@keyframes gl-edge-out { to { transform: scaleY(0); } }

/* A row with › to its detail: it dips on the press like an opening row,
 * and its › leans the way it goes, on the spring. */
.lpage .rows li.tap, .lpdetail .rows li.tap { transition: transform var(--gl-press) var(--ease); }
.lpage .rows li.tap:has(> .rowtap:active), .lpdetail .rows li.tap:has(> .rowtap:active) { transform: scale(.985); }
.lpage .chev::after, .lpdetail .chev::after { display: inline-block; transition: transform var(--gl-chev) var(--spring); }
.lpage li.tap:has(> .rowtap:active) .chev::after { transform: translateX(3px); }
