/* ==========================================================================
   Weg durch die Schichten (.flow): Platten wie bei yoga-frame
   (Aussehen: demo/plates.css), daneben eine Strecke mit einem Knoten je
   Station und der Erklärung. Alles richtet sich nach der Breite des Bildes;
   die Zeilen sind so hoch wie ihr Text, die Platten rücken mit.

   --unit    eine Einheit der Plattenzeichnung (288 breit)
   --level   Höhe der rechten Ecke einer Platte: dort sitzen Knoten und Name
   --drop    zusätzlicher Abstand an der Grenze zum Postfach (schmal: Platz für zwei Zeilen)
   --i       Platz der Platte von oben (obere liegen über unteren)
   --fold    Weg einer Platte bis in den geschlossenen Stapel (flow.js)
   --at      Lage der Station, an der die Marke steht (flow.js)

   .is-closed  Platten liegen noch aufeinander
   .is-live    ein Weg wurde gestartet: Es zählt nur, was schon erreicht ist
   .is-running er läuft gerade, .is-done er ist zu Ende
   Zeile: .is-here Marke ist dort, .is-seen war dort, .is-lit Strecke danach an
   ========================================================================== */

.flow {
  --travel: 1.5s;
  --glide: cubic-bezier(0.45, 0, 0.3, 1);
  --load: color-mix(in srgb, var(--c-signal) 85%, var(--c-ink));  /* Mail oder Befehl */
  container-type: inline-size;
  display: grid;
  gap: 1.5rem;
  margin: 0.5rem 0 0.75rem;
}
.flow-board {
  --plate: 43cqi;
  --rail: clamp(2rem, 9cqi, 3.75rem);
  --node: 1.5rem;
  --drop: 0px;
  --unit: calc(var(--plate) / 288);
  --level: calc(88 * var(--unit));
  --mid: calc(var(--plate) + var(--rail) / 2);
  position: relative;
}
.flow-rows { list-style: none; margin: 0; padding: 0 0 calc(var(--level) - 1.75rem); }
.flow-row {
  --row: 6.25rem;
  position: relative;
  z-index: calc(9 - var(--i));
  min-height: var(--row);
  padding-left: calc(var(--plate) + var(--rail));
}
/* Der Kern ist dicker und braucht nach unten entsprechend mehr Platz */
.flow-row--core { min-height: calc(var(--row) + 16 * var(--unit)); }
/* Die Grenze zum Postfach liegt unter der letzten Platte und ihrem Text */
.flow-row--last { min-height: calc(154 * var(--unit) + 1rem); margin-bottom: var(--drop); padding-bottom: var(--level); }
.flow-row--out { min-height: 0; }

/* Platten */
.flow .plate { position: absolute; left: 0; top: 0; width: var(--plate); height: auto; overflow: visible; transition: transform 1.8s var(--ease), opacity 0.8s var(--ease) 1.2s; }
.flow.is-closed .plate { transform: translateY(var(--fold)); }
.flow-row.is-here .plate { --p-edge: var(--load); --p-edge-width: 3; }
/* Gestrichelte Verbindung der linken und rechten Ecken bis zur nächsten Platte */
.flow-row:not(.flow-row--last, .flow-row--out)::before,
.flow-row:not(.flow-row--last, .flow-row--out)::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: calc(56 * var(--unit));
  left: 0;
  height: 100%;
  border-left: 1px dashed var(--c-line-strong);
}
.flow-row:not(.flow-row--last, .flow-row--out)::after { top: var(--level); left: calc(var(--plate) - 1px); }

/* Postfach: kleiner, gestrichelt und ohne Dicke, es liegt nicht auf dem Handy */
.flow .plate--out { --small: 0.7; top: calc(var(--level) * (1 - var(--small))); left: calc(var(--plate) * (1 - var(--small)) / 2); width: calc(var(--plate) * var(--small)); }
.plate--out .plate-top { stroke-width: 2; stroke-dasharray: 7 5; }
.plate--out .plate-glyph { stroke-width: 4; }
.flow-edge {
  position: absolute;
  inset: calc(-1 * var(--drop)) 0 auto;
  border-top: 1px dashed var(--c-line-strong);
  padding: 0.45rem 0 0 calc(var(--plate) + var(--rail));
  color: var(--c-ink-3);
  font-size: 0.8rem;
  line-height: 1.3;
}

/* Strecke und Knoten */
.flow-rail {
  position: absolute;
  top: calc(var(--level) + var(--node) / 2);
  left: calc(var(--mid) - 1px);
  width: 2px;
  height: calc(100% - var(--node));
  background: var(--c-line-strong);
}
.flow-row--last .flow-rail { height: calc(100% - var(--node) + var(--drop)); }
.flow-rail::after { content: ""; position: absolute; inset: 0; background: var(--load); transform-origin: var(--from, top); }
.flow.is-live .flow-row:not(.is-lit) .flow-rail::after { transform: scaleY(0); }
.flow-node {
  position: absolute;
  top: calc(var(--level) - var(--node) / 2);
  left: calc(var(--mid) - var(--node) / 2);
  display: grid;
  place-items: center;
  width: var(--node); height: var(--node);
  border: 1px solid var(--load);
  border-radius: 2px;
  background: var(--c-bg);
  color: var(--c-ink);
  font: 600 0.75rem/1 var(--font-mono);
}
.flow-node::before {
  content: "";
  position: absolute;
  right: calc(100% + 1px);
  width: max(0px, (var(--rail) - var(--node)) / 2 - 5px);
  border-top: 1px solid var(--c-line-strong);
}
.flow-row--out .flow-node::before { width: calc(var(--plate) * 0.15 + (var(--rail) - var(--node)) / 2 - 5px); }
.flow.is-live .flow-row:not(.is-seen) .flow-node { border-color: var(--c-line-strong); color: transparent; }

/* Name und Erklärung auf Höhe des Knotens; die Texte aller Wege liegen
   übereinander, damit die Zeile beim Wechseln gleich hoch bleibt */
.flow-text { position: relative; top: calc(var(--level) - 0.75rem); display: grid; align-content: start; padding-bottom: 1rem; }
.flow-name { grid-row: 1; color: var(--c-ink); font: 600 1.05rem/1.5rem var(--font-display); letter-spacing: -0.01em; transition: color 0.3s var(--ease); }
.flow-name small { margin-left: 0.5rem; color: var(--c-ink-3); font: 400 0.8rem/1 var(--font-sans); letter-spacing: 0; }
.flow-row.is-here .flow-name { color: var(--c-accent); }
.flow-text p { grid-area: 2 / 1; color: var(--c-ink-2); font-size: 0.95rem; line-height: 1.45; transition: opacity 0.5s var(--ease); }
.flow.is-live:not(.is-done) .flow-row:not(.is-seen) .flow-text p { opacity: 0; }
.flow[data-scenario="arrive"] [data-s]:not([data-s~="arrive"]),
.flow[data-scenario="archive"] [data-s]:not([data-s~="archive"]),
.flow[data-scenario="undo"] [data-s]:not([data-s~="undo"]),
.flow[data-scenario="offline"] [data-s]:not([data-s~="offline"]) { visibility: hidden; }

/* Die Marke: was gerade unterwegs ist */
.flow-token {
  position: absolute;
  z-index: 10;
  top: calc(var(--level) - 1rem);
  left: calc(var(--mid) - 1rem);
  display: grid;
  width: 2rem; height: 2rem;
  border-radius: 3px;
  background: var(--load);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--load) 22%, transparent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(var(--at, 0px));
  transition: opacity 0.3s var(--ease);
}
.flow-token svg { grid-area: 1 / 1; margin: 0.4rem; fill: none; stroke: var(--c-bg); stroke-width: 2; stroke-linejoin: round; }
.flow.is-running .flow-token { opacity: 1; transition: opacity 0.3s var(--ease), transform var(--travel) var(--glide); }
.flow.is-running .flow-rail::after { transition: transform var(--travel) var(--glide); }

/* Was auf den Platten geschieht */
.flow-mail { stroke: var(--load); }
.flow-mail rect { fill: var(--load); stroke: none; }
.flow-mail, .flow-rest { transition: transform 0.8s var(--ease), opacity 0.6s var(--ease); }
.flow[data-state~="away"] .flow-mail { transform: translateX(48px); opacity: 0; }
.flow[data-state~="away"] .flow-rest { transform: translateY(-35px); }
.flow-slot { transition: fill 0.4s var(--ease), stroke 0.4s var(--ease); }
.flow[data-state~="queued"] .flow-slot { fill: var(--load); stroke: var(--load); }
.flow-net { transition: opacity 0.4s var(--ease); }
.flow-cut { stroke: var(--c-warn); stroke-width: 5; opacity: 0; transition: opacity 0.4s var(--ease); }
.flow[data-state~="offline"] .flow-net { opacity: 0.35; }
.flow[data-state~="offline"] .flow-cut { opacity: 1; }
.flow-row.is-here .flow-live { stroke-dasharray: 7 5; animation: flow-live 1.2s linear infinite; }
@keyframes flow-live { to { stroke-dashoffset: -24; } }

/* Geschlossen: nur der Stapel ist zu sehen, das Übrige kommt nach dem Öffnen dazu */
.flow :is(.flow-rail, .flow-node, .flow-text, .flow-edge),
.flow-row::before, .flow-row::after { transition: opacity 0.8s var(--ease) 1.2s; }
.flow.is-closed :is(.flow-rail, .flow-node, .flow-text, .flow-edge, .plate--out),
.flow.is-closed .flow-row::before, .flow.is-closed .flow-row::after { opacity: 0; }
.flow.is-closed :is(.plate, .flow-rail, .flow-node, .flow-text, .flow-edge),
.flow.is-closed .flow-row::before, .flow.is-closed .flow-row::after { transition: none; }

@container (max-width: 30rem) {
  .flow-board { --plate: 39cqi; --rail: 2.5rem; --node: 1.375rem; --drop: 2.25rem; }
  .flow .choices button { flex-basis: 40%; }
  .flow-name { font-size: 1rem; }
  .flow-name small { display: block; margin: 0 0 0.3rem; }
  .flow-text { padding-bottom: 0.75rem; }
  .flow-text p { font-size: 0.875rem; line-height: 1.4; }
}
/* Sehr schmal oder stark vergrößerte Schrift: drei Zeilen an der Grenze */
@container (max-width: 17rem) {
  .flow-board { --drop: 4rem; }
}
